SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I need a little help, I have a veriable:
    $var = "<br>blablabla...";
    blablabla... is dynamic, so never the same, but there's always a <br> before that content, now I want to remove the first <br>, but in the dynamic content there are <br>'s, I want not to remove these too! So only remove the 1ste <br> of the string...
    any ideas

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try this:

    substr_replace($var, "", 0, 4)

  3. #3
    Gong!
    Join Date
    May 2000
    Location
    Helsinki, Finland
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by 7stud
    substr_replace($var, "", 0, 4)
    However, substr_replace function doesn't check whether there actually is a "<br>" in front of the string or not - if there isn't it would simply remove 4 characters. But, you can use regular expression to do this too::
    PHP Code:
    $var eregi_replace("^<br>"""$var); 
    Now, if $var = "<br>something", it would remove it, but if $var="something", it would leave it intact.
    HighCheats - game cheats, codes, tips and tricks for PC and various console platforms

  4. #4
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by hmahonen
    PHP Code:
    $var eregi_replace("^<br>"""$var); 
    This works fine!
    Thanx!

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    but there's always a <br> before that content
    My fault. I foolishly assumed what iBram007 said was true, and since string functions are more efficient that was what I suggested.


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
  •