paganotti
paganotti

Reputation: 5661

php extracting first image from html string, remove all images tag, and truncate html string

I save in database an html content from tinymce editor, so I would want display this html content on php page, but in beautiful way. I would want first check if in html string is present an image, if it is present then display it first in php page. Then I would want display some text on right of image, truncating it first 200 words, but it must maintain html because it is possible that are present also links not only simple text.

Is there a php library or php class for manipulating html and for truncating html string for "read more" functionality?

Upvotes: 3

Views: 997

Answers (1)

Flosculus
Flosculus

Reputation: 6946

This looks like a nice tool:

http://simplehtmldom.sourceforge.net/

Funnily enough it even has the example your looking for on the front page.

EDIT:

PHP actually comes with its own library for handling HTML documented at: http://docs.php.net/manual/en/book.dom.php Also take a look at http://code.google.com/p/phpquery/

Upvotes: 2

Related Questions