fork download
  1. <?php
  2.  
  3.  
  4. function str_replace_once($str_pattern, $str_replacement, $string){
  5.  
  6. if (strpos($string, $str_pattern) !== false){
  7. $occurrence = strpos($string, $str_pattern);
  8. return substr_replace($string, $str_replacement, strpos($string, $str_pattern), strlen($str_pattern));
  9. }
  10.  
  11. return $string;
  12. }
  13.  
  14. $string = 'Hello x World hello';
  15.  
  16. $term = 'hello';
  17.  
  18. str_replace_once($term, '', $string)
  19. );
Success #stdin #stdout 0.02s 24480KB
stdin
Standard input is empty
stdout
string(14) "Hello x World "