Author Topic: Help with article preview  (Read 28266 times)

Offline woden

  • Semi-Newbie
  • *
  • Posts: 58
    • PetFish.Net
Help with article preview
« 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

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

Offline Spaceman-Spiff

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,524
  • Gender: Male
Re: Help with article preview
« Reply #1 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);