hello, i am trying to replace alt="Image" with alt="<?=$row['title'];?> (there is space at the beginning and at the end of them) how can i do this? i am tried different ways but it did not work. $fullpageweb = str_replace(' alt="Image" ', ' alt="<?=$row['title'];?>" ', $fullpageweb); PHP: thanks
If you already have the $row array, then do it like this; $fullpageweb = str_replace(' alt="Image" ', ' alt=' . $row['title'] . ' ', $fullpageweb); PHP: If you use single quotes ( ' ' ) then PHP will not parse the string and will just dump whatever is inside them, if you use double quotes ( " " ) then PHP WILL parse the string and swap variables etc. In your case the variable was inside single quotes so PHP did not look for variables etc to replace, I just took the variable out of the string. Dan
Thank you for your help. instead of . $row['title'] . i have to use <?=$row['title'];?> is there anyway i can do that? thanks
i am still learning.... i wanted to use this <?=$row['title'];?> thinking i could use it at the output. i did not realize i can change it at the code before output. now.. i can not use $fullpageweb = str_replace(' alt="Image" ', ' alt=' . $row['title'] . ' ', $fullpageweb); PHP: instead i need to use $fullpageweb = str_replace(' alt="Image" ', ' alt=" . $title . ", $fullpageweb); PHP: but it does not work either. thanks
$fullpageweb = str_replace(' alt="Image" ', ' alt=" '. $title .' " ', $fullpageweb); PHP: That should work
This is how I would originally do it in my scripts: $fullpageweb = str_replace("alt=\"Image\"", "alt=\"$title\"", $fullpageweb); PHP: You can also try str_ireplace That replaces strings regardles of case