SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    server side text truncation

    Hi,

    I have been struggling with text truncation with html in the string. I am pulling a string of html from a mysql table and truncating the text using substr().That is simple enough, but when the string is truncated in the middle of an html entity funny stuff happens. I have played with this for a while but cannot seem to construct a function that works consistently to only truncate after an end tag.

    If some one could throw me a line that would be much appreciated.

    Thank you

  2. #2
    SitePoint Addict telos's Avatar
    Join Date
    Mar 2005
    Location
    192.168.2.34
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you only want text and you don't care about the HTML tags, than you could use strip_tags to get rid of the HTML.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestion Telos but the html is important for formatting and embedded links to external documents, etc... so strip_tags() is not an option for me.

  4. #4
    SitePoint Addict telos's Avatar
    Join Date
    Mar 2005
    Location
    192.168.2.34
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an article I ran across a while back - seems like it might help you. http://www.gsdesign.ro/blog/cut-html...king-the-tags/

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Telos. It seems to work ok. I will refine it a bit for my specific need but that is a huge help. Kudos.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •