fork download
  1. <?php
  2.  
  3. function pr($array_to_output)
  4. {
  5. print '<pre>';
  6. print_r($array_to_output);
  7. print '</pre>';
  8. }
  9.  
  10. //
  11. // Written by Patrick Rauchfuss
  12. class String
  13. {
  14. public static function stritr(&$string, $from, $to = NULL)
  15. {
  16. if(is_string($from))
  17. $string = preg_replace("'/\b$from\b/'i", $to, $string);
  18.  
  19. else if(is_array($from))
  20. {
  21. foreach ($from as $key => $val)
  22. self::stritr($string, $key, $val);
  23. }
  24.  
  25. return $string;
  26. }
  27. }
  28.  
  29.  
  30. $wordsTransform = array(
  31. 'shit' => 'ship'
  32. );
  33.  
  34. $string = "Rolling In The Deep\n
  35. \n
  36. There's a fire starting in my heart\n
  37. Reaching a fever pitch, and it's bringing me out the dark\n
  38. Finally I can see you crystal clear\n
  39. Go ahead and sell me out and I'll lay your SHIT bare";
  40.  
  41. $string = strtr($string, $wordsTransform);
  42.  
  43. pr(String::stritr($string, $wordsTransform));
  44.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<pre>Rolling In The Deep



There's a fire starting in my heart

Reaching a fever pitch, and it's bringing me out the dark

Finally I can see you crystal clear

Go ahead and sell me out and I'll lay your SHIT bare</pre>