用 php 只回显一个 div
我正在尝试制作一个脚本,仅回显包含 google 图像的 div。
$url = "http://www.google.com/";
$page = file($url);
foreach($page as $theArray) {
echo $theArray;
}
问题是这会回显整个页面。 我只想回显
和下一个最接近的
谢谢
I'm attempting to make a script that only echos the div that encolose the image on google.
$url = "http://www.google.com/";
$page = file($url);
foreach($page as $theArray) {
echo $theArray;
}
The problem is this echos the whole page.
I want to echo only the part between the <div id="lga">
and the next closest </div>
Note: I have tried using if's but it wasn't working so I deleted them
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用内置 DOM 方法:
Use the built-in DOM methods:
为此,您需要解析 DOM,然后获取您要查找的 ID。查看像这样的解析库 http://simplehtmldom.sourceforge.net/manual.htm
之后将您的 html 文档输入解析器,您可以这样称呼:
我认为,这将是您最快和最简单的解决方案。
In order to do this you need to parse the DOM and then get the ID you are looking for. Check out a parsing library like this http://simplehtmldom.sourceforge.net/manual.htm
After feeding your html document into the parser you could call something like:
That, I think, would be your quickest and easiest solution.