php str_replace 只匹配一次
php str_replace 只匹配一次 用户可能是在找如何利用 php 的str_replace只替换目标字符串的内容一次,而不是全部替换。[代码片段(11行)]
用户可能是在找如何利用 php 的str_replace只替换目标字符串的内容一次,而不是全部替换。
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://outofmemory.cn
- 上一篇:php 一个安全的快速写日志的函数
- 下一篇:PHP跨站刷票代码
精彩图集
精彩文章






