NYCPHP Meetup

NYPHP.org

[nycphp-talk] Blog Posts with Embedded Content

Hans Zaunere lists at zaunere.com
Tue Oct 7 17:27:13 EDT 2008


Hello,

So people post blogs, which may include a youtube link or image or href
embedded.

In one part of the application, they want to show only the first X number of
characters, before forcing a user to login.  So we need to cut the submitted
text at this character count, yet, of course, not cut in the middle of a
tag.

This has turned into a considerable annoyance and I'm wondering if anyone
has a quick tip/pointer to a resource to solve this - without writing
excessive text parsing code.

My general plan (although I hope someone has something better) is to:

-- write a function like DeltaOffsets( $Raw, $Stripped)  where $Raw is the
$Raw post and $Stripped is the post run through strip_tags.

-- the function would return an array with the positions relative to the
$Raw post of where the stripped text has started/stopped.

-- then upon writing to the browser, we could intelligently insert stripped
tags up to the cut-off-point of real text (ie, not counting the stripped
tags).

Although this seems like a lot of work for something that must be done all
the time, right?  Thoughts on how the other blog engines handle this?
There's got to be an easier way...?

Yes, security is another issue...

H





More information about the talk mailing list