Reputation: 219
I have to display a content from database.The content is added using an editor. I used the code below to display it
<?php echo $record['content'];?>
It displays like below
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>
style also displays with the content.How can I remove this?I only need text content that is the description only.I have to remove that style content.
I tried html_entity_decode
but no effect
Upvotes: 0
Views: 378
Reputation: 2960
echo(preg_replace('/<style[^>]*>(([^<]|[<[^\/]|<\/[^s]|<\/s[^t])*)<\/style>/i','',$record['content']));
I'm on mobile phone, so code is untested... but that's the idea...
EDIT Now tested the code, there was a missing ')' and added removal of newlines/returns after tag:
<?php
echo(preg_replace('/[\n\r ]*<style[^>]*>(([^<]|[<[^\/]|<\/[^s]|<\/s[^t])*)<\/style>[\n\r ]*/i','',$record['content']));
?>
Upvotes: 1
Reputation: 5196
try
echo preg_replace('/\s+/', ' ', preg_replace('/<[^>]*>/', ' ', $record['content']));
Upvotes: 0
Reputation: 570
Try this:
$string1=$record['content'];
$pos=strpos($string1,"<");
$string2=substr($string1,0,$pos);
I have not tried it. But it should work. This is in case you dont want the style tags.
Upvotes: 0