Php regular expression filtering is a parameter in the URL. how can I write it? There are the following URLs: http: // 127.0.0.1/c/1.php? Ft = x7cj: http: // 127.0.0.1/c/1. phphttp: // 127.0.0.1/c/1.php? Form = post php regular expression filtering a parameter in the URL. how can I write it?
There are the following URLs:
Http: // 127.0.0.1/c/1.php? Ft = x7cj
Http: // 127.0.0.1/c/1.php
Http: // 127.0.0.1/c/1.php? Form = post & ft = gy4e
Http: // 127.0.0.1/c/1.php? Form = post
Http: // 127.0.0.1/c/1.php? Ft = 7yd4r & form = post
Http: // 127.0.0.1/c/1.php? Form = post
For example, how can I use regular expressions to output the following php files on URLs in the above three formats?
$ Tjurl = "http: //". $ _ SERVER ['http _ host']. $ _ SERVER ['request _ URI '];
// How can I use a regular expression to filter URLs in the above three formats? * ** In the url parameter "ft = ***" is not a fixed letter or number and is randomly changed.
Echo "$ tjurl ";
Exit;
?>
------ Solution --------------------
PHP code
------ Solution --------------------
PHP code
$ Arr = array ('http: // 127.0.0.1/c/1.php? Ft = x7cj ', 'http: // 127.0.0.1/c/1.php? Form = post & ft = gy4e ', 'http: // 127.0.0.1/c/1.php? Ft = 7yd4r & form = Post'); print_r (array_map ('foo', $ arr); function foo ($ url) {$ ar = parse_url ($ url ); if (! Isset ($ ar ['query']) return $ url; parse_str ($ ar ['query'], $ arr); unset ($ arr ['FT']); return $ ar ['scheme ']. '://'. $ ar ['host']. $ ar ['path']. ($ arr? '? '. Http_build_query ($ arr ):'');}
------ Solution --------------------
Write in this way (comment out the following $ s to test the previous one)
$ S = 'http: // 127.0.0.1/c/1.php? Seed = add & ft = 7yd4r & form = post ';
$ S = 'http: // 127.0.0.1/c/1.php? Ft = x7cj ';
$ S = 'http: // 127.0.0.1/c/1.php? Form = post & ft = gy4e ';
$ S = 'http: // 127.0.0.1/c/1.php? Ft = 7yd4r & form = post ';
Echo preg_replace ('/([? &]) Ft = [^ &] + (&?) /E', '"$2" = ""? "": "$1" ', $ s );
People give you an array, but it makes it easier for you to test it.