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 關注
- 156 瀏覽
添加回答
舉報