PHP解析问题
这是我用来从网站抓取缩略图路径的代码,
$thumbslist = $xpath->query('//div[@class="g-catThumb"]/img/@src');
foreach($thumbslist as $f){
echo $f->nodeValue;
echo "<br/>";
}
我有以下输出:/toys/16462/medium.jpg
我该怎么得到只有16462。提前谢谢。
Here is code I use for grabbing thumbnails paths from a site
$thumbslist = $xpath->query('//div[@class="g-catThumb"]/img/@src');
foreach($thumbslist as $f){
echo $f->nodeValue;
echo "<br/>";
}
I have the following output: /toys/16462/medium.jpg
How should I get only 16462. Thaks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
explode()
来拆分字符串通过斜线进入数组,然后抓取你想要的部分。确保首先检查是否是
isset()
。You can use
explode()
to split the string by slashes into an array, and grab the piece you want.Make sure to check if it
isset()
first.