1 回答
TA贡献1876条经验 获得超6个赞
您可以使用此问题str_replace_first
中描述的实现,并迭代您的和数组,仅替换数组中每个值的一次出现:$find
$replace
$find
function str_replace_first($search, $replace, $subject) {
if (($pos = strpos($subject, $search)) !== false) {
return substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
$result = $string;
foreach ($find as $key => $search) {
$result = str_replace_first($search, $replace[$key], $result);
}
echo $result;
输出:
style1 is simply style4 text of the printing and style3 industry.
style2 has been the industry's standard style5 text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book.
- 1 回答
- 0 关注
- 127 浏览
添加回答
举报