fork(2) 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. return preg_quote($string);
  25. }
  26. }
  27.  
  28.  
  29. $wordsTransform = array(
  30. 'shit' => 'ship'
  31. );
  32.  
  33. $string = "Rolling In The Deep\n
  34. \n
  35. There's a fire starting in my heart\n
  36. Reaching a fever pitch, and it's bringing me out the dark\n
  37. Finally I can see you crystal clear\n
  38. Go ahead and sell me out and I'll lay your SHIT bare";
  39.  
  40. $string = strtr($string, $wordsTransform);
  41.  
  42. pr(String::stritr($string, $wordsTransform));
  43.  
Success #stdin #stdout 0.01s 20568KB
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 ship bare</pre>