Help me how to add multiple replace code while read text file.example "aaa" replace with "bbb" . "ccc" replace with "ddd" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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>"; } ?>

11th Mar 2023, 2:12 PM
Syafiq
Syafiq - avatar
2 Answers
+ 4
You can do this with a following statement: str_replace(find,replace,string,count)
11th Mar 2023, 3:19 PM
JaScript
JaScript - avatar
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>";     } ?>
12th Mar 2023, 2:29 AM
Syafiq
Syafiq - avatar