First, perhaps the string below
/do/comment_all.php?url=/korabl_vikingov.html
stored in the $ _SERVER ['REQUEST_URI'] variable.
Secondly, it is meaningless to check for a match using preg_match before replacing the same expression with the help of preg_replace , since if there is no match, there will be no replacement.
Thirdly, your regular schedule is wrong.
1) There is no indication of the beginning and end of a regular expression
2) Is the special character not escaped ?
As a result, your regular season (if you had not forgotten to designate its beginning and end) was looking for this:
/do/comment_all.phurl= /do/comment_all.phpurl=
The correct version of your regular expression is :
@\/do\/comment_all\.php\?url= @i
So, if you do not change your approach to the solution, and correct only obvious errors, then the solution is:
$request = $_POST['id']; $pattern = '@\/do\/comment_all\.php\?url= @i '; $urlstr = preg_replace($pattern, "", $request);
Or you can do it differently:
$urlstr = $_POST['id']; $url_array = parse_url($urlstr); # Теперь в $url_array у нас следующее: # Array # ( # [path] => /do/comment_all.php # [query] => url=/korabl_vikingov.html # ) parse_str($url_array['query'], $query_array); # Теперь в $query_array у нас следующее: # Array # ( # [url] => /korabl_vikingov.html # ) # Если идет обращение к /do/comment_all.php и есть get-параметр url, то: if ($url_array['path'] === '/do/comment_all.php' && isset($query_array['url'])) { # Присвоим его значение переменной $urlstr = $query_array['url']; # Содержимое переменной: /korabl_vikingov.html }
$_POST['id']? - etki