php - trim url(query string) -
I have a query string that is given below:
Now variable: In the query string, the page can be anywhere within the query string or at the beginning or middle or end (e.g., page = 9 or & amp; page = 9 & amp; or page = 9) anywhere.
Now, I need to remove page = 9 from my query string and get a valid query string.
wrote a function for this. Seems to work:
& lt ;? Php $ url = "http: //localhost/project/viewMember.php? Sort = y2xhc3m = & amp; square = mw == & page = 9"; // print http: //localhost/project/viewMember.php? Sort = Y2xhc3M = & amp; Class = mw == print changeURL ($ url) "\ N"; $ Url = "http: //localhost/project/viewMember.php? Sort = Y2xhc3M = & amp; page = 9 & amp; square = mw =="; // print http: //localhost/project/viewMember.php? Sort = Y2xhc3M = & amp; Class = mw == print changeURL ($ url) "\ N"; Function changeURL ($ url) {$ arr = parse_url ($ url); $ Query = $ arr ['query']; $ Pieces = explosion ('& amp;', $ query); ($ I = 0; $ i & lt; Count ($ piece); $ i ++) {if (preg_match ('/ ^ page = \ d + /', $ pieces [$ i])) Set ($ pieces [$ I]); } $ Query = implode ('& amp;', $ pieces); Return "$ arr [plan]: // $ arr [host] $ arr [user] $ arr [pass] $ arr [path]? $ $ Arr [fragment]"; }? & Gt;
Comments
Post a Comment