PHP搜索和替换多个文件、多个实例

PHP搜索和替换多个文件、多个实例,php,str-replace,Php,Str Replace,我正在尝试编写一个php脚本,它将更改多个文件中单词/短语的多个实例 我有一个收集变量的表单 这是我的剧本 $introname= $_POST['introname'] ; $introid= $_POST['introid'] ; $officeid= $_POST['officeid'] ; $introname= $_POST['introname'] ; $office= $_POST['office'] ; $email= $_POST['email'] ; $q="introl

我正在尝试编写一个php脚本,它将更改多个文件中单词/短语的多个实例

我有一个收集变量的表单

这是我的剧本

$introname= $_POST['introname'] ;
$introid= $_POST['introid'] ;
$officeid= $_POST['officeid'] ;
$introname= $_POST['introname'] ;
$office= $_POST['office'] ;
$email= $_POST['email'] ;


$q="intrologin.php";
$f=fopen($q,'r');
$c=fread($f,10000);
$final = str_replace("jojointroname", $_POST['introname'], $c);
$final = str_replace("jojointroid", $_POST['introid'], $c);
$final = str_replace("jojoofficeid", $_POST['officeid'], $c);
$final = str_replace("jojooffice", $_POST['office'], $c);
fclose($f);
$f=fopen($q,'w');
fwrite($f,$final);
fclose($f);


$p="introprocessing.php";
$f=fopen($p,'r');
$c=fread($f,10000);
$final = str_replace("jojoemail", $_POST['email'], $c);
fclose($f);
$f=fopen($p,'w');
fwrite($f,$final);
fclose($f);
当我运行此脚本时,脚本的第二部分运行良好并更改电子邮件,但脚本的第一部分仅更改“office”,而不是前面的3个变量


我是否需要为每次更改创建一个单独的组,还是我缺少了什么?

这是因为每次调用str\u replace时,您都会给它一个原始字符串
$c
,因此当您将该字符串指定给
$final
时,它会覆盖以前的更改。这应该起作用:

$final = str_replace("jojointroname", $_POST['introname'], $c);
$final = str_replace("jojointroid", $_POST['introid'], $final);
$final = str_replace("jojoofficeid", $_POST['officeid'], $final);
$final = str_replace("jojooffice", $_POST['office'], $final);

先生,您是一位学者和绅士。谢谢你的帮助help@Joel考虑接受答案。下面是如何返回此处并对勾号/复选标记执行相同操作,直到其变为绿色。这会通知社区,找到了解决方案。否则,其他人可能会认为问题仍然悬而未决,并可能希望发布(更多)答案。