【PHP】str_replaceを使って文字列を置換する
以下がサンプルコードです。
<?php $str = str_replace('before', 'after', 'text before text'); echo $str; // 出力:text after text ?>
第一引数に配列を使えば複数の値を指定することもできます。
<?php $search = array('l', 'o'); $str = str_replace($search, 'x', 'hellow world'); echo $str; // 出力:hexxxw wxrxd ?>