Re: getting content exceprts from the database
| From: | Per Jessen | Date: | Mon, 26 Apr 2010 11:24:02 +0000 |
| Subject: | Re: getting content exceprts from the database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304598@lists.php.net to get a copy of this message | ||
Ashley Sheridan wrote:
> Here's the rub though. As the content is in HTML form, I can't just
> grab the first 100 characters and display them as that could leave an
> open tag without a closing one, potentially breaking the page. I
> could use strip_tags on the 100-character excerpt, but what if the
> excerpt itself broke a tag in half (i.e. <acronym title="something">
> could become <acron )
>
> The only solutions I can see are:
>
>
> * retrieve the entire article, perform a strip_tags and then
> take the excerpt
> * use a regex inside of mysql to pull out only the text
>
- parse the HTML and extract the text elements.
If the HTML is well-formed, this is relatively easily done with XSL, if
not, you might need to use Beautiful Soup or similar.
--
Per Jessen, Zürich (16.1°C)