. How can I delete page = 1111 in a = ddddd & page = 1111?

Source: Internet
Author: User
For help. How can we delete page = 1111 in a = ddddd & amp; page = 1111. This is a url address. the parameter string is truncated. A = ddddd $ page = 2334 & amp; www = 2222 page = 1111 & amp; m = 3234 & amp; o = r2345a = ddddd $ wc = 2334 & a for help. How can we delete page = 1111 in a = ddddd & page = 1111.
This is a url address. the parameter string is truncated.

A = ddddd $ page = 2334 & www = 2222
Page = 1111 & m = 3234 & o = r2345
A = ddddd $ wc = 2334 & page = plo

All three methods are possible. Front, middle, and end.

How can we get rid of page = parameter values in regular expressions.

I wrote this regular expression for half a day. Page =. * & | \ s, or no match.

Give me some advice. Share:
------ Solution --------------------
$ S = 'a = ddddd & page = 2334 & www = 100 ';
$ S = 'page = 1111 & m = 3234 & o = r2345 ';
$ S = 'a = ddddd & wc = 2334 & page = PLO ';

// This is more formal
Parse_str ($ s, $ );
Unset ($ a ['Page']);
Echo http_build_query ($ a), PHP_EOL;

// Regular expressions are more alternative
Echo preg_replace ('/(&?) Page = [^ &] + (&?) /E', '"$2 "? "$1": "" ', $ s );

------ Solution --------------------
Reference:
Quote: reference:

$ S = 'a = ddddd & page = 2334 & www = 100 ';
$ S = 'page = 1111 & m = 3234 & o = r2345 ';
$ S = 'a = ddddd & wc = 2334 & page = PLO ';

// This is more formal
Parse_str ($ s, $ );
Unset ($ a ['Page']);
Echo http_build_query ($ a), PHP_EOL;

// Regular expressions are more alternative
Echo preg_replace ('/(&?) Page = [^ &] + (&?) /E', '"$2 "? "$1": "" ', $ s );


You are amazing. It's strange. How did you learn that well. I have been using php for several years, and I have to check regular expressions on Baidu. How did you learn it?

Http_build_query ($ a), PHP_EOL; this is not very common. What do you think. I can't think of it. Why. I'm not satisfied!


If you ask Baidu every time and try writing it by yourself without combining your experience and knowledge, you will never think of some amazing ideas.

 
$s = 'a=ddddd&page=2334&www=2222';
//$s = 'page=1111&m=3234&o=r2345';
//$s = 'a=ddddd&wc=2334&page=plo';
 
echo implode('&', array_filter(explode('&', $s), create_function('$str', 'return substr($str, 0, 5) !== "page=";')));

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.