【发布时间】:2015-09-09 20:06:34
【问题描述】:
我想编辑string 的variable。但我做不到好。代码:
$mysite = 'mysite'; //name of site
$myurl = 'http:/mysite.com'; //url of website
$metaauthor = ''; // meta name author;
$metatitle = 'Online CV Builder'; // meta name title
$metacopy = 'Javid Karimov'; // meta name copyright
$metakeywords = 'CV, PDF, ONLINE, RESUME'; // meta name keywords
$allowcv = '2'; // how many cv's user can create
$keyword = 'cv, pdf, resume, create cv online'; // keyword for creating security key
$mailto = 'mail@gmail.com'; // send to mail in contact php
我这样改变(它工作):
$str = file_get_contents('../sys/sets.php');
//replace something in the file string
$str = str_replace($mysite, $sitenamexx, $str);
$str = str_replace($myurl, $siteurlxx, $str);
$str = str_replace($metaauthor, $metaavtorxx, $str);
$str = str_replace($metacopy, $metacopyxx, $str);
$str = str_replace($metatitle, $metatitlexx, $str);
$str = str_replace($metakeywords, $metakeywxx, $str);
$str = str_replace($allowcv, $allowcvxx, $str);
$str = str_replace($keyword, $keywxx, $str);
$str = str_replace($mailto, $mailtoxx, $str);
//write string
$wok = file_put_contents('../sys/sets.php', $str);
if($wok) {
echo 'Changed<br/>';
}
else {
echo 'Error<br/>';
}
问题:如果string 为空(例如:$mysite = '';),那么它不会改变。我该如何解决?可能有另一种方法吗?我试过fopen(),fgets()的方式,这样我必须使用array,但是我无法使用它。
【问题讨论】:
-
用 php 编辑 php 脚本通常是个坏主意
-
好吧,如果这是个坏主意,你能给出什么建议?
-
我认为尝试在非空字符串中搜索空字符串是行不通的
-
你的意思是我不能用任何方式改变它?
-
我的大脑>.$thing 更新为
$thingxx?或者'$thing'到'$thingxx'?