SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove the last <br /> of a given string - issues

    This is something to do with the ckeditor, it keeps adding a <br /> at the end and, for any reason, I cannot get rid of it consistently.

    Sometimes I get a < at the end of my string;
    Sometimes I get all well cleared.

    I'm using this at the moment, but perhaps the lack of consistency could have something to do with the white spaces that could have been added or somethinhg?

    Anyway, here's the thing:
    PHP Code:
    substr_replace($noticia->primeiro_paragrafo_noticia ,"",-7); 
    Is there a way do this on a way that we can garantee that there are no whitespaces involved? Could we trim, and then do this substr_replace and then "un trim" or something?

    I have tried like so as well, but here I cannot get any removal at all:
    PHP Code:
    rtrim($noticia->primeiro_paragrafo_noticia'<br />'); 

    Thanks a lot,
    Marcio

  2. #2
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try a:

    PHP Code:
    rtrim(trim($var), '<br />'); 

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2009
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked like a charm! How have you came with this idea?

    Thanks a lot,
    Márcio

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    rtrim is not the correct function to use here imho.
    Consider the following:

    Code:
    brrrrrrrrrr<br />
    Since rtrim removes all characters that are in the second argument occuring at the end of the string the whole text above would be removed (since all the characters therein are in '<br />')

    A better way would be to use
    PHP Code:
    $var preg_replace('/<br\s*?\/?>\s*$/'''$var); 
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •