1
我想用replaceword.txt文件替換searchword.txt文件中的一些字符串,但用我的PHP代碼它只能替換前兩個字符串,我想替換文件中的所有字符串。str_replace在file.txt中的字符串與另一個file.txt
這裏是我的PHP代碼:
$txt_s = file_get_contents("searchword.txt");
$txt_s = explode(";", $txt_s);
$txt_r = file_get_contents("replaceword.txt");
$txt_r = explode(";", $txt_r);
$term = str_replace($txt_s, $txt_r, $last_tmp_);
這裏是我的searchword.txt文件看起來像:
hello; modern; corn; banana; apple;
這裏是我的replaceword.txt文件看起來像:
goodbye; fashionable; popcorn; monkey; sweet;
我怎樣才能取代所有的字符串,不只是前兩個字符串?或者可能是任何不同的方式來做到這一點,請讓我知道。
我測試你的代碼,它的工作原理以及在我結束。嘗試'str_ireplace'不敏感的情況。看到[這裏](http://php.net/manual/en/function.str-ireplace.php) – ROMMEL 2013-05-03 20:39:35