Posted By

kyabas on 05/27/11


Tagged

replace once strreplace


Versions (?)

str_replace_once


 / Published in: PHP
 

  1. function str_replace_once($needle , $replace , $haystack){
  2. // Looks for the first occurence of $needle in $haystack
  3. // and replaces it with $replace.
  4. $pos = strpos($haystack, $needle);
  5. if ($pos === false) {
  6. // Nothing found
  7. return $haystack;
  8. }
  9. return substr_replace($haystack, $replace, $pos, strlen($needle));
  10. }

Report this snippet  

You need to login to post a comment.