PHP ファイルの文字列を置換 strtr(置換する文字列, 置換する連想配列)

2018/09/18(0) 143

PHP ファイルの文字列を置換 strtr(置換する文字列, 置換する連想配列)

目次

ファイルの文字列を複数置換 strtr(置換する文字列, 置換する連想配列)
ファイルの文字列を置換 strtr (置換する文字列, 置換前, 置換後)

ファイルの文字列を複数置換 strtr(置換する文字列, 置換する連想配列)

ファイルを読み込んで、文字列を一括で置換。

$fileName = 'test.php';

$arrayReplace = array(
'testname.html' => 'testname_amp.html'
,'className' => 'className_amp'
);

$buff = file_get_contents($fileName);
$buff = strtr($buff, $arrayReplace);
file_put_contents($fileName, $buff);



ファイルの文字列を置換 strtr (置換する文字列, 置換前, 置換後)