第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

php str_replace() 搜索中的重復(fù)詞

php str_replace() 搜索中的重復(fù)詞

PHP
精慕HU 2023-04-02 11:16:24
嘗試使用搜索和替換一些內(nèi)容str_replace()。如果 the 是唯一的,它工作正常$find,但是一旦$find有重復(fù)的單詞,整個(gè)事情就搞砸了。例如 The style1will be applyed on both$find[0] && $find[1]因?yàn)閮烧叨际荓orem Ipsum,同樣適用于dummy。如何處理這種情況?$find = Array(    [0] => Lorem Ipsum     [1] => Lorem Ipsum     [2] => typesetting     [3] => dummy     [4] => dummy );$replace = Array(    [0] => style1    [1] => style2    [2] => style3    [3] => style4    [4] => style5);$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.            Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,            when an unknown printer took a galley of type and scrambled it to make a type specimen book.";$result = str_replace($find,$replace,$string);echo $result;
查看完整描述

1 回答

?
HUX布斯

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.



查看完整回答
反對(duì) 回復(fù) 2023-04-02
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)