function str_replace_limit($search, $replace, $subject, $limit=-1) { if (is_array($search)) { foreach ($search as $k=>$v) { $search[$k] = ‘`‘ . preg_quote($search[$k],‘`‘) . ‘`‘; } } else { $search = ‘`‘ . preg_quote($search,‘`‘) . ‘`‘; } return preg_replace($search, $replace, $subject, $limit); }
$search:要替换的字符串或者数组
$replace:要替换的值
$subject:要替换的文本
$limit:替换的此数字
时间: 2024-10-11 07:37:11