count() and str_replace()
Posted: Tue May 25, 2004 7:44 am
I'm making a l33tifier for my site, and this is a part of the code I use in the l33tifier function:
The string you put in the function call is called $str. As you can see, this is the code replacing "you" with either "yuo" or "j00". Some "you"'s changes to "yuo" and some to "j00".
But something is wrong in there. When I run open the l33tifier page it takes ages for the page to load, so I think that the for loop is infinite by some reason.
I can't find what's wrong in there. Maybe a foreach loop could solve the problem? I don't know how those work though. Do you know what's wrong?
Code: Select all
$words = explode(" ", $str);
for($i = 0; $i <= count($words); $i++)
{
$temp = rand(0, 1);
if($temp == 0) $word = "j00";
if($temp == 1) $word = "yuo";
$words[$i] = str_replace("you", $word, $words[$i]);
}
$str = implode(" ", $words);But something is wrong in there. When I run open the l33tifier page it takes ages for the page to load, so I think that the for loop is infinite by some reason.
I can't find what's wrong in there. Maybe a foreach loop could solve the problem? I don't know how those work though. Do you know what's wrong?