简体   繁体   中英

url pattern matching php

I have a url of the format /?var1 = val1&var2 = val2;

I want to check for the presence of just var2 = val2 in the url using php. How can that be done?

You can use the $_GET superglobal

if(!empty($_GET['var2']) && $_GET['var2'] == 'val2')) // do something

do this

if (isset($_GET['var2']))  // check if exist
{ 
  if ($_GET['var2'] == val2) // do something
}

If this is not the QUERY_STRING for the request (in which case you should just use $_GET as @Spechal said ), you can use parse_str() . It " uses the same mechanism that PHP uses to populate the $_GET , $_POST , etc. variables. "

See also parse_url() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM