简体   繁体   中英

How to get a Substring from a String after a specific word

I'm looking to get a Substring from a String: The best way to explain this is with following example:

$string = 'locations?city=London';
if (strpos($string,'city=') !== false) 
{
   // now here I need something to get London in a string
}
parse_str( parse_url( 'locations?city=London', PHP_URL_QUERY ), $params );

print_r( $params );

// outputs: Array ( [city] => London ) 

echo $params['city'];

// outputs London

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