David Eno
David Eno

Reputation: 147

PHP str_replace( ) won't work in user defined function

When I try to make a user defined function using str_replace it has no effect. Components of the same code work perfectly when not in a user defined function. The following shows a simple representation of my problem.

<?php
function replacelist($thetext) {
    $seachfor = array("crackers","soup");
    $replacewith = array("shapes","stew");
    $newtext = str_replace($searchfor, $replacewith, $thetext);
    return $newtext." - plus some test text";
    }
?>


<?php
$mytext="Animal crackers in my soup";

$newphrase = replacelist($mytext);

echo $newphrase;
?>

The above results in

Animal crackers in my soup - plus some test text

Any help gratefully received.

Thanks David

Upvotes: 0

Views: 111

Answers (1)

pdw
pdw

Reputation: 8866

Spell $seachfor correctly and it will work.

Upvotes: 3

Related Questions