使用file_get_contents时如何从特定标签获取内容 [英] How to get content from specific tags when using file_get_contents

查看:336
本文介绍了使用file_get_contents时如何从特定标签获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个.txt文件,称为cache.txt.它包含一些信息,我需要从<span class="date">**THESE**</span>标记中获取内容.有任何想法吗? 谢谢.

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.

推荐答案

您可以使用简单的HTML DOM

示例:

cache.txt

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
?>

这篇关于使用file_get_contents时如何从特定标签获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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