php - str_replace string with a file.txt -


i'm sorry have asked before, different output. here previous question answered. inefficient.

i want searchword , replaceword in 1 file. think method more easier. think code should this:

$txt_search = file_get_contents("replaced.txt"); $txt_search = array_map( 'trim', explode("=", $txt_s) ); $txt_replace = file_get_contents("replaced.txt"); $txt_replace = array_map( 'trim', explode(";", $txt_r) ); $term = str_replace($txt_s, $txt_r, $last_tmp_); 

and inside replaced.txt file should this:

hello=hi; modern=fashionable; apple=banana; 

so result want 'hello' replaced 'hi'. should change code? or there way?

this should give map of replacements

$arr = parse_ini_string(str_replace(";", "\n", file_get_contents("replaced.txt"))); 

if have control on contents of replaced.txt file change ;'s on newlines , and use parse_ini_file("replaced.txt"); same array, might little saner maintain.

then can replacements with

$term = str_replace(array_keys($arr), array_values($arr), $last_tmp_); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -