PHP string manipulation (3 posts)

  1. WarAxe
    Posted 10 years ago #

    Okay, here'a good one to test the PHP coders amoung us.

    I want to read $post_content from a post and display only a portion of it if it exceeds a certain length (we'll say 1000 characters). But, I'm freaked out about just using this: echo(substr($post_content,0,999)); ...because I don't want it to cut off in the middle of an xhtml tag (or something equally error promising).

    I had thought about iterating through $page_content and counting the '<' and '>' (much like a running stack variable or counting 10's in Black Jack)... but I still may end up cutting off before a beginning tag has goten to its ending tag.

    Any ideas?

  2. Kafkaesqui

    Posted 10 years ago #

    My the_excerpt Reloaded plugin makes use of WP's pre-existing function balanceTags(). If it helps:


  3. WarAxe
    Posted 10 years ago #

    Yeah... I think that'll do the trick. I'll let everyone know what it looks like when I'm done. :-)


Topic Closed

This topic has been closed to new replies.

About this Topic