Splitting HTML Strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dris
Forum Newbie
Posts: 1
Joined: Sun May 18, 2003 10:19 am

Splitting HTML Strings

Post 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!
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

chop() & strip_tags()

These might help.
Post Reply