Posted By


kyabas on 05/27/11

Tagged


Statistics


Viewed 495 times
Favorited by 0 user(s)

str_replace_once


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.