Forum Moderators: coopster

Message Too Old, No Replies

quick php question

re str_replace looping through an array

         

HelenDev

10:38 am on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to replace all instances of the ampersand with the word "and". It's not working at the moment though, but here is what I've got so far...

$postarray = array("bits & bobs","this & that","hen & chicken");

print_r($postarray);

foreach ($postarray as $value) {
$value = str_replace("&", "and", $value);
}

print_r($postarray);


Any help would be much appreciated.

ph_eze_nouz

11:28 am on Jun 25, 2004 (gmt 0)

10+ Year Member



Here it goes ;)

$postarray = array("bits & bobs","this & that","hen & chicken");

print_r($postarray);

for ($i=0; $i<(count($postarray)); $i++)
{
$postarray[$i] = str_replace("&", "and", $postarray[$i]);
}
echo "<p>";
print_r($postarray);

Give it a try ;) Works fine here ;)

HelenDev

11:57 am on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, that works a treat :)

HelenDev

12:11 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A problem has occured though :(

When I use this code with the actual $_POST array, it causes my form to hang and the email to not get sent. Any idea why this might be?