1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用此問(wèn)題str_replace_first
中描述的實(shí)現(xiàn),并迭代您的和數(shù)組,僅替換數(shù)組中每個(gè)值的一次出現(xiàn):$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 關(guān)注
- 151 瀏覽
添加回答
舉報(bào)