SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Cutting off text

    Hello, I've been pondering this problem for some time now. I have created a news posting system with full BB code and all. On the front page, I only display the first 200 chars.

    Here's the problem, if there is BB code in there, it might cut it with a tag open and it'll stay on for the rest of the page.

    For example, someone posts something in bold than the code cuts it off half way in their bold section, and so the rest of the page is left bold.

    Thank you in advance.

  2. #2
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any way to remove the tags (temporarily) and then post up the cut off text?
    [--Wings--]

  3. #3
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by koomann
    Is there any way to remove the tags (temporarily) and then post up the cut off text?
    would you suggest that?

  4. #4
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you process the BB code to HTML (for final output) and then keep track of the opened tags, and close them all after the 200 characters have been printed. You should also not use 200 characters just like that, you should exclude the characters of the BB tags when counting.
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |

  5. #5
    $postcount++; koomann's Avatar
    Join Date
    Feb 2003
    Location
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would you suggest that?
    Well, yeah, pretty much. I see your problem, and changing the BB tags to HTML would still land you with your same perdicament.
    [--Wings--]

  6. #6
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function strip_code($message){
        return 
    preg_replace("#\<(.+?)>#is"''$message);

    I coded that (so simple) and it works great. Any suggestions to make it faster?

  7. #7
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrWoot
    PHP Code:
    function strip_code($message){
        return 
    preg_replace("#\<(.+?)>#is"''$message);

    I coded that (so simple) and it works great. Any suggestions to make it faster?
    Mr Woot, doesn't that go awfully wrong when someone might enter:

    HTML Code:
    <tab<table>le> 
    <!-- or -->
    A > B where C < D    (without using &gt; and &lt;)
    ?
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |

  8. #8
    SitePoint Zealot mrWoot's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yjanse
    Mr Woot, doesn't that go awfully wrong when someone might enter:

    HTML Code:
    <tab<table>le> 
    <!-- or -->
    A > B where C < D    (without using &gt; and &lt;)
    ?
    My script changes < and > to &gt; and &lt;. So, I'm good. Right?


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
  •