SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Break String *after* IMG or EMBED tags?

    Hello everyone,

    I created a mini "blog feed" for the front page of my clients website. I want to be able to truncate each of the posts and add a "read more" link the end. Easy enough job, accept each blog post may or may not contain 'IMG' (auto resized) and 'EMBED' (youtube vids) tags and I want to ensure the string is NOT broken on those tags or it will display an empty link.

    So my question is, what would be the best way to tackle the problem?


    Kind regards and thanks,

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    strip_tags is what you're looking for I think, This page should help....
    http://php.net/manual/en/function.strip-tags.php

    That would remove ALL HTML from the preview.

    There is a little bit of regular expression further down the page. Look in to that too. Powerful stuff
    You'll need that if you want to show some HTML but only whole tags.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey! funny enough I went with strip_tags in the end. Then I opted to prepend a video or image onto the string with the title "attached media! - seems to work nice

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Nice, and probably the fastest method processor-wise too
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah its a neat solution, I really should have thought of it sooner however


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
  •