如何从特定单词后的字符串中获取子字符串 [英] 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
这篇关于如何从特定单词后的字符串中获取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文