【发布时间】:2010-11-19 20:45:58
【问题描述】:
我有一个混合了 html、文本和 php 的 PHP 文件,包括名称 areaname-house.php。文件的 text/html 部分在不同的地方包含字符串“areaname”。另一方面,我有一个带有城市名称的字符串数组。
我需要一个 PHP 脚本,它可以获取每个字符串(来自字符串数组),复制 areaname-house.php 并创建一个名为 arrayitem-house.php 的新文件,然后在新创建的文件中,替换字符串“areaname " 与数组项。我已经能够在以下代码中使用示例变量(城市名称)作为测试成功地创建克隆文件的第一部分:
<?php
$cityname = "acton";
$newfile = $cityname . "-house.php";
$file = "areaname-house.php";
if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}else{
// open the $newfile and replace the string areaname with $cityname
}
?>
【问题讨论】:
标签: php file replace clone keyword