Hye! This is my first question here, so sorry in advance if I don’t get it right.
I want to insert pictures from a gallery in a description text by using #pic1# (#pic2# and so on) in the text and replace it with
Here is the code:
<?
$myString =$art[0][page_text];
$pics=mysql_query_assoc("select * from pages_galerie where id_page='".$id_page."'");
$count= count($pics);
for ($i=0; $i < $count; $i++) {
$search='#pic'.$i+1.'#';
$img=$pics[$i][pic];
$newString = str_replace($search, "<img src=".SITE_URL."pics/medium/".$img.">", $myString);
}
?>
It doesn’t work!
What do I do wrong?
Try this
http://codepad.org/2NBlkDN9
You were performing the replacement in
$myStringand storing it in$newStringeverytime. Hence only the last replacement had any effect on the final output. I have initialzed$newStringwith$myStringand performed the replacement in$newString.