0
Help me how to add multiple replace code while read text file.example "aaa" replace with "bbb" . "ccc" replace with "ddd"
<?php $input=fopen("myfile.txt", "r"); while(!feof($input)) { echo fgets($input). "<br>"; } ?>
2 Respuestas
+ 4
You can do this with a following statement:
str_replace(find,replace,string,count)
0
<?php
$input = fopen("myfile.txt", "r");
while(!feof($input)) {
//echo fgets($input). "<br>";
$str = fgets($input);
$searchVal = array("aaa", "bbb", "ccc");
$replaceVal = array("fff", "ggg", "hhh");
$res = str_replace($searchVal, $replaceVal, $str);
echo ($res). "<br>";
}
?>