Let me see where the ARRAY is wrong.
Function replace_text_wps ($ text ){
$ Replace = array (
// 'Keyword '=> 'replaced keyword'
'Wordpress' => 'wordpress ');
Optional tmpfilename1_'1.txt '; // format: prom | http://www.baidu.com
$ Str = file_get_contents ($ tmpfilename); // Obtain the content
$ Arr = explode ("\ n", $ str); // store a branch to an array
Foreach ($ arr as $ row) {// traverse each row
$ Keys = explode ("|", $ row );
$ Replace [$ keys [0] = $ keys [1]; // why is it not added successfully?
}
$ Replace ['excerpt'] = 'cool ';
$ Text = str_replace (array_keys ($ replace), $ replace, $ text );
Return $ text;
}
Echo replace_text_wps ('Prom dresses wordpress excerpt ');
?>
Reply to discussion (solution)
Print_r ($ replace );
You can also use $ arr = file ($ tmpfilename );
Replace
$ Str = file_get_contents ($ tmpfilename); // Obtain the content
$ Arr = explode ("\ n", $ str); // store a branch to an array
The two have the same effect, and the file is more concise.
Foreach ($ arr as & $ row) {// Add reference
$ Keys = explode ("|", $ row );
$ Replace [$ keys [0] = $ keys [1];
}