代码
<?
$moban =file_get_contents('m.html');for($i=0;$i<5;$i++)
{
$gewei=rand(1,99);
$shiwei=rand(100,999);
$htmlcontent = str_replace('{a}',"$gewei",$moban);
$htmlcontent=str_replace('{a1}',"$shiwei",$htmlcontent);
$htmlname="$i.html";
file_put_contents($htmlname,$htmlcontent);
echo "文件创建成功".$i.".html<br>";
}
?>
m.html模板里面内容为 {a} <br>{a}<br>{a1}
生成的东西是 1 1 222
我在生成的时候发现{a}的内容都是相同的,我要得到的效果是
生成的东西为 1 2 222
这里只是举一个例子。那位大牛解决一下,谢谢。
<?
$moban =file_get_contents('m.html');for($i=0;$i<5;$i++)
{
$gewei=rand(1,99);
$shiwei=rand(100,999);
$htmlcontent = str_replace('{a}',"$gewei",$moban);
$htmlcontent=str_replace('{a1}',"$shiwei",$htmlcontent);
$htmlname="$i.html";
file_put_contents($htmlname,$htmlcontent);
echo "文件创建成功".$i.".html<br>";
}
?>
m.html模板里面内容为 {a} <br>{a}<br>{a1}
生成的东西是 1 1 222
我在生成的时候发现{a}的内容都是相同的,我要得到的效果是
生成的东西为 1 2 222
这里只是举一个例子。那位大牛解决一下,谢谢。
这儿要替换三个地方,前两个地方是相同的
你却要求替换结果不一样(1 2 222),所以你得改那个m.html
将第二个{a}改变{b}
将上面函数添加这句
$geweiTest = '2';
$htmlcontent = str_replace('{b}',$geweiTest,$moban);
你再测试,结果就是你想要的1 2 222