从另一个页面获取div的元素(PHP) [英] Getting elements of a div from another page (PHP)

查看:281
本文介绍了从另一个页面获取div的元素(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有第一页:

 < div id =div1>这是文字之一< / div> ; 

< div id =div2>这是text two< / div>

< div id =div3>这是文字三< / div>

现在我想要得到div 1的元素,它会返回这是文本之一,我该怎么做?解析方案

您可以在PHP中使用DOMDocument:

 <?php 

$ doc = new DomDocument;

//我们需要在引用id
$ doc-> validateOnParse = true之前验证我们的文档;
$ doc-> loadHtml(file_get_contents('http://google.com/bla.php'));

var_dump($ doc-> getElementById('div1'));

?>


So I have page one:

<div id="div1">This is text one</div>

<div id="div2">This is text two</div>

<div id="div3">This is text three</div>

Now I want to get the elements of div one, that it will return This is text one, how can I do that?

解决方案

You can use DOMDocument in PHP:

<?php

$doc = new DomDocument;

// We need to validate our document before refering to the id
$doc->validateOnParse = true;
$doc->loadHtml(file_get_contents('http://google.com/bla.php'));

var_dump($doc->getElementById('div1'));

?>

这篇关于从另一个页面获取div的元素(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆