例如,我有一个.txt文件,名为cache.txt。它包含一些信息,我需要从<span class="date">**THESE**</span>
标签获取内容。有任何想法吗?
感谢。
答案 0 :(得分:2)
您可以使用Simple HTML DOM
示例:强>
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
?>
答案 1 :(得分:0)
**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];
?>