fork(1) download
  1. <?php
  2.  
  3. function str_lreplace($neddle, $replacement, $haystack) {
  4. return substr_replace($haystack, $replacement, strpos($haystack, $neddle), strlen($neddle));
  5. }
  6.  
  7. function str_rreplace($neddle, $replacement, $haystack) {
  8. return substr_replace($haystack, $replacement, strrpos($haystack, $neddle), strlen($neddle));
  9. }
  10.  
  11. echo str_lreplace("foo", "", "foobarfoo\n");
  12. echo str_rreplace("foo", "", "foobarfoo\n");
  13.  
  14. ?>
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
barfoo
foobar