如何用str_replace
或用php字符串替换单词preg_match
?我的代码是:
$html = crawl_website($self_url."linkboxmain.php");
$getout = "usrid:<?=$_GET['tag'] ?>";
$string = str_replace("usrid:",$getout,$html);
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/linkboxshow.php', $string);
上面的代码不起作用!
我想替换"usrid:"
为"usrid:<?=$_GET['tag'] ?>"
,然后将其放入linkboxshow.php文件。
crawl_website()
是获取页面html的函数。
将$_GET
gets评估为变量,将其转义或用单引号引起来,应该很好。
'usrid:<?=$_GET[\'tag\'] ?>';
也可能值得一看http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double。因为还有一些路要走..
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句