News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Help with article preview

Started by woden, February 17, 2009, 04:10:49 PM

Previous topic - Next topic

woden

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...";

Spaceman-Spiff

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);

Advertisement: