从字符串中获取一部分 [英] Getting a part from a string
本文介绍了从字符串中获取一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从网站收集所有CatID ... URL结构是...
I am trying to collect all CatIDs from a site...the URL structure is...
我对此感兴趣categoryId
,在这种情况下为12436777
I am interested in it categoryId
which is in this case is 12436777
我的问题是
哪一个最好,正则表达式或字符串爆炸?
Which is best, Regex or string explode??
如果使用正则表达式,请帮助我,我对此很不好..
if regex, please help me, I am very bad on it..
此外,我还必须考虑这样的网址
Also, I have to consider that URLs like
我尝试了
$array = explode("http://www.abc.com/family/index.jsp?categoryId=", $loc);
foreach ($array as $part) {
$zee[] = $part[1];
}
但是它什么也没给我..
but it gives me nothing ..
感谢帮助.
推荐答案
您可以使用 parse_url 可靠地为您提供查询字符串:
You can use parse_url to reliably give you the query string:
$parts = parse_url('http://www.abc.com/family/index.jsp?categoryId=12436777');
,然后 parse_str 解析出变量:
parse_str($parts['query'], $result);
echo $result['categoryId']; // outputs 12436777
这篇关于从字符串中获取一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文