Simple Machines Community Forum

Archived Boards and Threads... => Archived Boards => Parham's PHP Tutorials => Topic started by: woden on February 17, 2009, 04:10:49 PM

Title: Help with article preview
Post by: woden on February 17, 2009, 04:10:49 PM
I want to snatch about 200 characters from mysql table row "content' to use as a preview for articles.
This code (below) is working ok but if there is html code for images I end up with a very short description.
How can I make it count the characters AFTER the html tags are stripped, instead of before?

I know there has to be a way, anything is possible with php  :D


Quote
$pdescription = trim(strip_tags((substr($row['content'],0,200)),'<b>,<br>'));
echo "$pdescription...";
Title: Re: Help with article preview
Post by: Spaceman-Spiff on March 03, 2009, 06:09:08 PM
A bit late answer, but...

$pdescription = substr(strip_tags(trim($row['content']), '<b><br>'), 0, 200);

or you can make it longer, but easier to read:

$pdescription = trim($row['content']);
$pdescription = strip_tags($pdescription, '<b><br>');
$pdescription = substr($pdescription, 0, 200);