milepile
milepile

Reputation: 141

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
}

Upvotes: 1

Views: 403

Answers (1)

Varol
Varol

Reputation: 1858

parse_str( parse_url( 'locations?city=London', PHP_URL_QUERY ), $params );

print_r( $params );

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

echo $params['city'];

// outputs London

Upvotes: 5

Related Questions