我正在尝试将示例 HTML 输出转换为纯文本,但我不知道如何操作。我使用 file_get_contents 但我尝试转换的页面返回的结果最相似。
$raw = "http://localhost/guestbook/profiles.php";
$file_converted = file_get_contents($raw);
echo $file_converted;
配置文件.php
<html>
<head>
<title>Profiles - GuestBook</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<!-- Some Divs -->
<div id="profile-wrapper">
<h2>Profile</h2>
<table>
<tr>
<td>Name:</td><td> John Dela Cruz</td>
</tr>
<tr>
<td>Age:</td><td>15</td>
</tr>
<tr>
<td>Location:</td><td> SomewhereIn, Asia</td>
</tr>
</table>
</div>
</body>
</html>
基本上,我试图回显类似的内容(纯文本,无样式)
Profile
Name: John Dela Cruz
Age: 15
Location: SomewhereIn, Asia
但我不知道怎么办。 :-( 。请帮助我,先谢谢你们了。
编辑:由于我只关注页面的内容,无论它是样式的还是纯文本的,有没有办法使用 file_get_contents() 仅选择(参见下面的代码)?
<h2>Profile</h2>
<table>
<tr>
<td>Name:</td><td> John Dela Cruz</td>
</tr>
<tr>
<td>Age:</td><td>15</td>
</tr>
<tr>
<td>Location:</td><td> SomewhereIn, Asia</td>
</tr>
</table>
Use php 条带标签 http://php.net/manual/en/function.strip-tags.php
如果 strip_tags 不起作用,那么也许您可以使用正则表达式来提取您想要的信息。
尝试使用 PHP预匹配 http://php.net/manual/en/function.preg-match.php with /(<td>.*?<\/td>)/
作为模式
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)