Page 1 of 1

Splitting HTML Strings

Posted: Sun May 18, 2003 10:19 am
by Dris
Alright, here's kind of a tough problem. Let's say I've got a lengthy string that contains HTML. Let's say that I want to get the first 400 letters from the string. But the tricky thing is doing that without splitting HTML tags in half. Also, if there's an element still open at the end, it needs to be closed. For example:

Code: Select all

Blah blah blah <a href="http://ww
That would be a bad thing. This is also a possible problem:

Code: Select all

Blah blah blah <b>blah blah
A <b> tag is opened, but it isn't closed. Does anyone know how to get around these problems? Thanks, I appreciate any help!

Posted: Sun May 18, 2003 12:46 pm
by m3mn0n
chop() & strip_tags()

These might help.