Re: [PHP] replacing part of string with values in array

2001-07-12 Thread Brian White

Shoot from the hip response... untested

function resolveParts( $str, $partsArray )
{
 // explode the original $str based on 'PART'
 $stringBits = explode( 'PART', $str );

 //Ok. So now we have two arrays. The length of partsArray
 // should be one less than stringBits

 $blended = array( array_shift( $stringBits ));

 while ( $stringBits )
 {
 $blended[] = array_shift( $partsArray );
 $blended[] = array_shift( $stringBits );
 }

 return implode( $blended, "" );
}






At 01:30 13/07/2001 +0200, Gregor Jaksa wrote:
>hello,
>
>ok heres the thing ;)
>lets say i have array("part1", "part2", "part3", "part4");
>now i have string like
>$string = "here's PART and heres PART, another PART here and final PART
>here";
>now i wanna replace first PART in string with part1 from array and second
>PART with part2 from array ...
>one more thing is that i dont know how many parts there will be in string ..
>but i know that array and string will have the same number of parts ;)
>
>help plz :)
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

-
Brian White
Step Two Designs Pty Ltd - SGML, XML & HTML Consultancy
Phone: +612-93197901
Web:   http://www.steptwo.com.au/
Email: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] replacing part of string with values in array

2001-07-12 Thread Gregor Jaksa

hello,

ok heres the thing ;)
lets say i have array("part1", "part2", "part3", "part4");
now i have string like
$string = "here's PART and heres PART, another PART here and final PART
here";
now i wanna replace first PART in string with part1 from array and second
PART with part2 from array ...
one more thing is that i dont know how many parts there will be in string ..
but i know that array and string will have the same number of parts ;)

help plz :)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]