PHP解析问题

发布于 2024-11-15 07:33:03 字数 300 浏览 3 评论 0原文

这是我用来从网站抓取缩略图路径的代码,

$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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最单纯的乌龟 2024-11-22 07:33:03

您可以使用 explode() 来拆分字符串通过斜线进入数组,然后抓取你想要的部分。

$segments = explode('/', $f->nodeValue);
echo $segments[1]; // Second segment

确保首先检查是否是 isset()

You can use explode() to split the string by slashes into an array, and grab the piece you want.

$segments = explode('/', $f->nodeValue);
echo $segments[1]; // Second segment

Make sure to check if it isset() first.

等数载,海棠开 2024-11-22 07:33:03
echo array_pop(explode('/', dirname($f->nodeValue)));
echo array_pop(explode('/', dirname($f->nodeValue)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文