2013-12-17 37 views
0
<?php 
    $html = file_get_contents('http://xpool.xram.co/index.cgi'); 
    echo $html; 
?> 

我想使用php在遠程網站上的標記中獲取信息。只有標籤。使用PHP從遠程站點獲取特定標記

我發現這個小字符串非常適合檢索整個網站源文件。但是,我只想得到一小部分。我怎樣才能過濾出所有其他標籤,並只獲得我需要的一個標籤?

+2

http://stackoverflow.com/questions/960841/how-to-use-dom-php-parser –

回答

1

我建議使用PHP DOM解析器。 (http://simplehtmldom.sourceforge.net/manual.htm

require_once ('simple_html_dom.php'); 

$html = file_get_contents('http://xpool.xram.co/index.cgi'); 

$p = $html->find('p'); // Find all p tags. 

$specific_class = $html->find('.classname'); // Find elements with classname as class. 

$element_id = $html->find('#element'); // Find element with the id element 

閱讀文檔,有可用噸的其他選項。

相關問題