日期:2014-05-17 浏览次数:20523 次
/**
+----------------------
* 只替换字符串中关键字一次
+----------------------
* @param string $needle 需替换的字符串
* @param string $replace 目标字符串
* @param string $haystack 原始字符串
+----------------------
* @return string
+----------------------
*/
function str_replace_once($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}