Change variables content

hi all

i want to replace contents of “$divs” with “$allimages”.

i tried


<?
$divs = "<div></div>";
$allimages = "<div>"."<img src='' id='image1' />"."<img src='' id='image2' />"."<img src='' id='image3' />"."</div>";
$imgs = str_replace('$div','$allimages');
echo $imgs;
?>

but it doesnt works

vineet

Try this

$content = "test <div></div> test";
$search  = "<div></div>";
$replace = "<div><img src='' id='image1' />"."<img src='' id='image2' />"."<img src='' id='image3' /></div>";
$imgs = str_replace($search, $replace, $content);
echo $imgs;

ps. check str_replace manual page for more details

thansk gvre

it works fine.

so it means str_replace doesnt works without 3rd parameter

vineet

Look at this example:


$ones = "1";
$numbers = "012345678910";

// do not quote the variables if you use them
// requires 3 arguments, what do you replace ones with?
// a string containing a *

$no_ones = str_replace($ones, '*', $numbers );

// is the equivalent of :
// $no_ones = str_replace('1', '*', $numbers );

echo $no_ones;
// 0*23456789*0



You need to study the examples in the online manual very carefully : [fphp]str_replace[/fphp]

thanks cups

for this guidance

vineet