Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Regex problem..

  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Regex problem..

    Hey guys.. having some problem with this regex..... example..

    Original text:

    Code:
    Text here:<BR>&nbsp;&nbsp;More text
    I am trying to remove the "<BR>&nbsp;&nbsp;" part but also account for lowercase, <br />/<br/>'s & also zero or more &nbsp; & not always just the two; but all my code seems to do is remove the <BR> tag & leave the &nbsp;'s.......

    Here is what I have tried..

    Code:
    $ff = preg_replace('~<br(/| /)?(&nbsp;)*>~i', ' ', $ff);
    also tried..

    Code:
    $ff = preg_replace('~(<br(/| /)?(&nbsp;)*)>~i', ' ', $ff);
    ..but they both gave the same result.

    Thanks for any help!

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Try:
    PHP Code:
    $ff preg_replace('#<br(/| /)?>|&nbsp;#i'' '$ff); 
    dumpfi

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks.. that worked; but I end up with the items replaced with 3 spaces instead of one.

  • #4
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Maybe thats because you have three things in the string being change to a space.......

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try
    PHP Code:
    $ff preg_replace('#<br(/| /)?>(?:&nbsp;)*#i'' '$ff); 
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thank you! That worked a charm!


  •  

    Posting Permissions

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