Mohammad Alipour Mohammad Alipour - 4 months ago 7
PHP Question

How to replace a word with a php string with str_replace or preg_replace

How to replace a word with a php string with

str_replace
or
preg_match
?
my code is :

$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);


above code not work!!

I want to replace
"usrid:"
with
"usrid:<?=$_GET['tag'] ?>"
and then put it to linkboxshow.php file.

crawl_website()
is a function to get html of a page.

Answer

As Cris85 answered. you should put $_GET in single quata like : 'usrid:<?=$_GET[\'tag\'] ?>' your problem solves if you change :

$getout = "usrid:<?=$_GET['tag'] ?>";

with

$getout = 'usrid:<?=$_GET[\'tag\'] ?>`;
Comments