0

我是 php 的新手(昨天开始),我有一个不错的 html/css 背景和一点 js,所以我想试一试。

我正在尝试构建一个简单的应用程序来自学 php,并且我想从另一个站点引用一段 html,例如 div :

<div id="name"> <p>Sam</p> </div>在“http://www.example.com/about.php”页面上

我正在尝试的是<?php echo file_get_contents("http://www.example.com #name"); ?>正确的方法吗?

我也无法确定是否更好使用include echoecho file_get_contents

抱歉这么基本的问题

4

1 回答 1

0

这可以用 来完成DOMDocument,这里有一个例子:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://example.com/');

// get the element that has id=name
$result = $doc->getElementById('name');

echo $result->nodeValue; // prints: Sam

// or print out $result to see all of the properties
print_r($result);
于 2012-10-09T18:29:14.280 回答