2014-03-19 47 views
0

我不能让strip_tags工作,我真的试图改变位置,语法,我通常使它工作,但这里不工作。为什么?strip_tags在这个例子中不工作

<?PHP 
$sum_string = $row_lastitem['summary']; 
$sum_string = strip_tags($sum_string); 
$sum_string = (strlen($sum_string) > 255) ? substr($sum_string,0,252).'...' : $sum_string; 

$sum_string = nl2br($sum_string); 

echo $sum_string; ?> 

的HTML有:像在我的错误

<p>this is a example</p> 
<p>line 2 </p> 

可有人点请。

即使这不会工作

<?PHP 
    $sum_string = $row_lastitem['summary']; 
    $sum_string = strip_tags($sum_string); 

    echo $sum_string; ?> 
+0

'$ row_lastitem ['summary']'的原始值是什么?也许它包含像'$ lt;'而不是'<'的实体? – Barmar

+0

原始值是那里的问题,复制并从数据库

这个贴是一个例子

线2

回答

0

好的解决方案:

对不起相关只是发现。 Why doesn't strip_tags work in PHP?

html_entity_decode需要。谢谢

<?PHP 
$sum_string = $row_lastitem['summary']; 


$sum_string = strip_tags(html_entity_decode($sum_string)); ; 
$sum_string = (strlen($sum_string) > 255) ? substr($sum_string,0,252).'...' : $sum_string; 

$sum_string = nl2br($sum_string); 

echo $sum_string; ?> 
+0

如果这是需要的,这意味着我的意见是正确的:你的数据库中包含的实体,而不是原始的HTML字符。 – Barmar

+1

这意味着插入数据库的代码调用'htmlentities()'。这通常是糟糕的设计 - 应该在显示时使用,而不是在存储时使用。 – Barmar

+0

好的,会改变这种感谢 –

相关问题