Forum Moderators: coopster

Message Too Old, No Replies

Can you guys help me with my ob_start problem?

         

haryanto

2:09 am on Mar 20, 2004 (gmt 0)

10+ Year Member



Hi guys,

I tried to do a string replace in my document but it failed. I tried to replace 2 animals monkey and cow.
It works when I remove 'return (str_replace("cow", "bull", $buffer));' which means I only can replace 'monkey'

How do we replace as many animals as we want?

<?php
function callback($buffer)
{
return (str_replace("monkey", "apes", $buffer));
return (str_replace("cow", "bull", $buffer));
}
ob_start("callback");
?>
monkey kills cow
<?php
ob_end_flush();
?>

Birdman

2:21 am on Mar 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the function ends once you return something. Str_replace allows arrays so you should be able to put the find/replace values into an array first.

function callback($buffer)
{
$find = array("monkey","cow");
$replace = array("apes","bull");
return str_replace($find, $replace, $buffer);
}

haryanto

5:10 am on Mar 20, 2004 (gmt 0)

10+ Year Member



Works like magic!

Thank you bird, I owe you some birdfeed!