Reputation: 313
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.
Upvotes: 0
Views: 199
Reputation: 23880
The $_GET
gets evaluated as a variable, escape or enclose it in single quotes and should be good to go...
'usrid:<?=$_GET[\'tag\'] ?>';
Also might be worth checking out http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double. because there are a few ways to go..
Upvotes: 1
Reputation: 110
Try it like this:
$html = crawl_website($self_url."linkboxshow.php");
$getout = "usrid:".isset($_GET['tag']) ? $_GET['tag'] : ''."";
$string = str_replace("usrid:",$getout,$html);
Upvotes: 1