I'm trying to make a 1337ifier for my site. You type in some text and press a button, and the text is converted to 1337sp33k. But:
When you use str_replace() or ereg_replace() to change for example "you" to "yuo", it changes all occurences of "you". But I want to change some "you" to "yuo" and some to "j00". How would I do that? I guess I could use explode() in some way, but I don't know how.
1337ifier
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$replaceWord = array('you'=>array('yuo','j00'));
foreach($replaceWord as $word => $rep)
{
$max = preg_match_all("=\b$word\b=i",$string);
preg_replace("=\b$word\b=i",$rep[mt_rand() % sizeof($rep)],$string,1);
}