How to write a parameter in the php regular expression filter URL?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.