Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String to Leet (1337) Speak in PHP

Tags:

string

php

Does anyone know where I can find a good starting point to code a function that would take a string and convert it to leet speak?

function stringToLeetSpeak($string) {
  // Logic

  return $leetString;
}
like image 792
Kirk Ouimet Avatar asked Dec 10 '25 22:12

Kirk Ouimet


1 Answers

You can use strtr to translate certain characters:

$output = strtr($str, 'let', '137');

Or use str_replace with arrays:

$output = str_replace(array('l','e','t'), array('1','3','7'), $str);

With this you can also replace strings and not just single characters:

$output = str_replace(array('hacker'), array('hax0r'), $str);
like image 188
Gumbo Avatar answered Dec 12 '25 13:12

Gumbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!