Jump to content

Extracting a paragraph (minus the HTML)


tHud

Recommended Posts

Hello :)

 

$row[longdescription] contains a description of a product (complete with HTML mark-up).

 

I would like to display the first 250 characters in the results of a search. I would also like to remove any images that may crop up.

 

This is what I have so far...

echo strip_tags(html_entity_decode(substr(preg_replace('/<img[^>]*>/Ui', '', $row[longdescription]), 0, 250)));

 

The thing is (as you guys can probably already see), it also counts the HTML mark-up as characters and I get very different outputs (especially if an image occurs).

 

I'd appreciate if you could advise me as to the correct way of doing this.

 

Thank you :)

 

Link to comment
https://forums.phpfreaks.com/topic/248013-extracting-a-paragraph-minus-the-html/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.