非常に単純なコード スニペットを設定しました。
$string = 'Some random words. Some more random, very random words.';
$words = explode(" ", $string);
for ($i = 0; $i < count($words); $i++) {
$word = $words[$i];
$words[$i] = str_replace(".", "!", $word);
$words[$i] = str_replace(",", "?", $word);
}
print_r($words);
出力は次のとおりです。
Array
(
[0] => Some
[1] => random
[2] => words.
[3] => Some
[4] => more
[5] => random?
[6] => very
[7] => random
[8] => words.
)
2 番目の関数だけがstr_replace()
文字列に影響するのはなぜですか? 2番目を削除するとstr_replace()
、最初のものは完全に機能します。の使用法ではありstr_replace()
ませんが、非常に単純に間違ったことをしていると思います。
ちなみに、私はpreg_replace()
配列を認識して渡してstr_replace()
いますが、この特定の状況について聞きたいです:)。
編集: 迅速な対応に感謝します。私はそのような問題を恥じていますが、最初は本当に目を引きませんでした. みんな、ありがとう!Mike Brant さんによる最初の正解を受け入れます。