str_replace count option REALLY not working

Discussion in 'PHP' started by offthedome, Nov 19, 2011.

  1. #1
    The php str_replace function works if I don't include the "count" option, but I actually want to use the count option.

    I even copied and pasted the code from w3schools and php.net directly into my source and it's not working. Here are examples that are not working:

    
    
    $str = str_replace("ll", "", "good golly miss molly!", $count);
    echo $count; //Should echo "2"
    //
    //
    $arr = array("blue","red","green","yellow");
    print_r(str_replace("red","pink",$arr,$i));
    echo "Replacements: $i"; //Should echo "Replacements: 1"
    
    PHP:
     
    offthedome, Nov 19, 2011 IP
  2. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #2
    Which version of PHP you have? The $count parameter was added in PHP 5.0.0, I think...
     
    bogi, Nov 19, 2011 IP
  3. offthedome

    offthedome Active Member

    Messages:
    446
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    95
    #3
    I am not home to check but my host is 1and1. I do know that the function str_ireplace brings up an error message if that is a clue.
     
    offthedome, Nov 19, 2011 IP
  4. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #4
    bogi, Nov 19, 2011 IP
  5. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #5
    Yes looking on php.net, the $count param was added in 5.0.0:

    http://uk.php.net/str_replace

    Looks like your on PHP4. Try adding phpinfo(); to a php file and loading it in the browser to see the current php config.
     
    mfscripts, Nov 22, 2011 IP