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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Some preg_replace() help.

    I've been tinkering around, but I'm not very experienced with using regexes. I've got some preg_replaces in place that format the HTML pretty nicely, but I have a problem I can't seem to take care of.

    I need anything between
    Code:
    <li>
    and
    Code:
    </li>
    to have all newlines, tabs, and carriage returns removed.

    I currently have code like this:
    Code:
    <li><a href="##">Stuff</a>
    
    </li>
    
    <li><a href="##">...
    I'd like to get that formatted back to:
    Code:
    <li><a href="##">Stuff</a></li>
    <li><a href="##">...

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    You could do something like this:
    PHP Code:
    $str = <<< STR
    <li><a href="##">Stuff</a>

    </li>

    <li><a href="##">...
    STR;
    $str preg_replace('/<li>(.*?)<\/li>/sie',"'<li>' . str_replace(array(\"\\r\",\"\\n\",\"\\t\"),'','\\1') . '</li>'",$str);
    echo 
    $str


  •  

    Posting Permissions

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