使用没有HTML内容的PHP保存txt文档

时间:2011-05-26 16:44:09

标签: php html

现在的文件是这样的:

<p>User friendly buttons and IR Remote Control for easy control&nbsp;</p>
<p>Quality stereo headset enables user to enjoy hi-fi dynamic sound&nbsp;</p>
<p>Replaceable, rechargeable Li-polymer battery&nbsp;</p>
<p>Specs Video transmission frequency: 2414, 2432, 2450, 2468&nbsp;</p>
<p>Transmission distance: Approx 100m in open space&nbsp;</p>
<p>Bitmap Audio carrier wave: 6.0Mhz, 6.5mHz, + 50Khz&nbsp;</p>
<p>&nbsp;</p>
<p>S/N Ratio: 50-70 db&nbsp;</p>
<p>Diplay: True Color Micro LCD&nbsp;</p>
<p>Resolution: Full color 922k pixels, 640*480&nbsp;</p>
<p>Viewing Angle: Diagonal 32 degree&nbsp;</p>
<p>Virtual Image Size: 80inches at 2M away&nbsp;</p>
<p>Contrast: 64:1, Color Depth: 24 bit &nbsp;</p>

我想获得相同的文件,但只是文本(carrefull有像&amp; lt那样的东西,我希望它们是“&lt;”

3 个答案:

答案 0 :(得分:5)

<?php
$str = html_entity_decode(strip_tags($str));
?>

答案 1 :(得分:4)

$html = '<p>Your &lt; html &gt;  &nbsp; here</p>';
$text = strip_tags($html);
$text = html_entity_decode($text);
echo $text;

输出:Your < html > here

剥离代码doc:http://us.php.net/manual/en/function.strip-tags.php

Html Entity Decode doc:http://php.net/manual/en/function.html-entity-decode.php

答案 2 :(得分:0)

PHP函数strip_tags将删除所有<p>html_entity_decode将修复您的&lt;和co。