问题
For example i have one .txt file, called cache.txt. It contains some information, and i need to get content from <span class="date">**THESE**</span>
tags. Any ideas?
Thanks.
回答1:
You can use Simple HTML DOM
Example:
cache.txt
<span class="abc">Lorem Ipsum</span>
<span class="date">THESE</span>
<span class="def">Dolor sit amet</span>
file.php
<?php
include 'simple_html_dom.php';
$html = file_get_html('cache.txt');
echo $html->find('span[class=date]',0); //Output: THESE
?>
回答2:
**Check this out it will bring the result**
//cache.txt
<span class="date">**THESE**</span>
//index.php
<?php
$dom = new DOMDocument();
$dom->load('cache.txt');
$xml = simplexml_import_dom($dom);
$data = $xml->xpath('/span');
echo $data[0][0];
?>
来源:https://stackoverflow.com/questions/9282931/how-to-get-content-from-specific-tags-when-using-file-get-contents