html - PHP's preg_replace returns null when replacing underscores with white spaces -


i have webpage includes hyperlink follows:

$name = "hello world"; echo "<a href='page.php?name='". preg_replace(" ", "_", $name) "'> bla bla </a>" 

this generates following link successfully:

...page.php?name=hello_world 

in page.php try reverse operation:

if($_server[request_method] == "get"){ $name = $_get['name']; //testing if problem echo $name; //now here's problem: $string = preg_replace("_", " ", $name); echo $string; } 

the $name echoes correctly $string null i've tried possible combinations ~~ , // , [_] , \s , using $_get directly like:

preg_replace("_", " ", $_get['name']); 

none of them worked. problem has burned of day. appreciated.

preg_replace accepts regular expression it's first arguments. neither " " nor "_" valid regular expressions.

in case can use str_replace.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -