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 ).
- /**
- *
- * Query URL string processing
- * @ Author: fc_lamp
- * @ Blog: http://fc-lamp.blog.163.com/
- * @ Param str $ key main parameter
- * @ Param str $ value parameter value
- * @ Param str $ query string (this value is not required)
- * @ Param str $ page_key page number parameter (when paging, the page number will be passed in GET, so you need to delete it)
- * @ Internal
- * If the character contains a key, the key in the original string is deleted and assigned a new value.
- * If the input value of the character key is NULL, the KEY is deleted.
- */
- Function query_str ($ key, $ value = '', $ query ='', $ page_key = 'page ')
- {
- $ Query = empty ($ query )? $ _ SERVER ['query _ string']: $ QUERY;
- If (empty ($ query ))
- {
- $ Query = "? $ Key = ". urlencode (" $ value ");
- } Else
- {
- Parse_str ($ query, $ q );
- If (isset ($ q [$ page_key])
- {
- Unset ($ q [$ page_key]);
- }
- If (isset ($ q [$ key])
- {
- Unset ($ q [$ key]);
- }
- If ($ value = NULL)
- {
- $ Query = '? '. Http_build_query ($ q );
- } Else
- {
- If (! Empty ($ q ))
- {
- $ Query = '? '. Http_build_query ($ q). "& $ key =". urlencode ("$ value ");
- } Else
- {
- $ Query = "? $ Key = ". urlencode (" $ value ");
- }
- }
- }
- Return $ query;
- }
|