2012-12-17 154 views
0

我必须从数据库中显示内容。使用编辑器添加内容。 我用下面的代码来显示它如何从文本中删除样式

<?php echo $record['content'];?> 

它显示象下面

description 
<style type="text/css"> 
body { background-color: #fff; padding: 0 20px; color:#000; font: 13px/18px Arial, sans-serif; } 
a { color: #360; } 
h3 { padding-top: 20px; } 
ol { margin:5px 0 15px 16px; padding:0; list-style-type:square; } 
#player1_wrapper{ 
description border:2px solid #B5B5B5; 
} 
</style> 

风格也与content.How显示我可以删除吗?我只需要文本内容,这只是说明我必须删除该风格的内容。 我试图html_entity_decode但没有效果

+2

您的意思是说明?只要 ?? –

+0

可能是以前的div没有正确完成。你可以给一点以前的代码? –

+0

或者,也许你只想要 body {background:#FFF; } – asitha

+1

是否要隐藏完整的 body {background:#FFF; }?或者只是标签? – user7282

0

试试这个:

editted:

$string1=$record['content']; 
$pos=strpos($string1,"<"); 
$string2=substr($string1,0,$pos); 

我还没有尝试过。但它应该工作。这是在你不想要样式标签的情况下。

+0

它也需要风格文本的计数也.. $ length是996 – asitha

+0

风格标签是否保存在数据库中? –

+0

是的..它存储在数据库中 – asitha

1
echo(preg_replace('/<style[^>]*>(([^<]|[<[^\/]|<\/[^s]|<\/s[^t])*)<\/style>/i','',$record['content'])); 

我的手机,所以代码是未经测试...但是这是想法...

编辑现在测试的代码,有一个缺少“)”,并添加去除换行/退货后标记:

<?php 


echo(preg_replace('/[\n\r ]*<style[^>]*>(([^<]|[<[^\/]|<\/[^s]|<\/s[^t])*)<\/style>[\n\r ]*/i','',$record['content'])); 

?>