- function str_replace_once($needle, $replace, $haystack) {
- // Looks for the first occurence of $needle in $haystack
- // and replaces it with $replace.
- $pos = strpos($haystack, $needle);
- if ($pos === false) {
- // Nothing found
- return $haystack;
- }
- return substr_replace($haystack, $replace, $pos, strlen($needle));
- }
- //该片段来自于http://www.codesnippet.cn/detail/120920135821.html
来源: http://www.codesnippet.cn/detail/120920135821.html