Summary of PHP

Source: Internet
Author: User
Summary of PHP

We have all encountered such a situation: a WEB application page has many search conditions, and sometimes a parameter corresponds to many values, or has a strong relationship between superiors and subordinates. for example, the rental network: house type parameters include: one room, one room, two rooms, etc. At this time, it is troublesome to give the correct URL parameter to a certain filter condition. in order to do repetitive work not all day long, we have written the following method. For example, we use the rental housing network example for reference (note that the following is only a demonstration, so we do not pay attention to the specifications ). Area: no limitation (''), area 1 (area1), area 2 (area2), area 3 (area3 )....... rent: Unlimited (''), less than 500 (cost 1), 500-800 (cost 2 )....... style: Unlimited (''), apartment (style1), ordinary apartment (style2 ).... the corresponding href value of Tag a is: "> unlimited"> zone 1 "> zone 2 ..... "> no limitation"> apartment "> in actual situations, tags of ordinary residences must be dynamically output. As long as the key (request parameter) and value (request parameter) values are consistent, then oh K :).Welcome to approval(More here: http://fc-lamp.blog.163.com/blog/static/17456668720128275633639 ).


  1. /**
  2. *
  3. * Query URL string processing
  4. * @ Author: fc_lamp
  5. * @ Blog: http://fc-lamp.blog.163.com/
  6. * @ Param str $ key main parameter
  7. * @ Param str $ value parameter value
  8. * @ Param str $ query string (this value is not required)
  9. * @ Param str $ page_key page number parameter (when paging, the page number will be passed in GET, so you need to delete it)
  10. * @ Internal
  11. * If the character contains a key, the key in the original string is deleted and assigned a new value.
  12. * If the input value of the character key is NULL, the KEY is deleted.
  13. */
  14. Function query_str ($ key, $ value = '', $ query ='', $ page_key = 'page ')
  15. {
  16. $ Query = empty ($ query )? $ _ SERVER ['query _ string']: $ QUERY;
  17. If (empty ($ query ))
  18. {
  19. $ Query = "? $ Key = ". urlencode (" $ value ");
  20. } Else
  21. {
  22. Parse_str ($ query, $ q );
  23. If (isset ($ q [$ page_key])
  24. {
  25. Unset ($ q [$ page_key]);
  26. }
  27. If (isset ($ q [$ key])
  28. {
  29. Unset ($ q [$ key]);
  30. }
  31. If ($ value = NULL)
  32. {
  33. $ Query = '? '. Http_build_query ($ q );
  34. } Else
  35. {
  36. If (! Empty ($ q ))
  37. {
  38. $ Query = '? '. Http_build_query ($ q). "& $ key =". urlencode ("$ value ");
  39. } Else
  40. {
  41. $ Query = "? $ Key = ". urlencode (" $ value ");
  42. }
  43. }
  44. }
  45. Return $ query;
  46. }

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.