1337ifier

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

1337ifier

Post by Dingbats »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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);
}
not tested
Post Reply