Regex help

Discussion in 'PHP' started by i3urn, Aug 11, 2012.

  1. #1
    Im in the middle of creating a simple blog system using a wysiwyg editor and when i submit a post a want to remove the background-color: rgb(235, 235, 235); from inside the style="" but leave everything else thats inside the style alone.

    So say i have:
    
    <div style="font-size: 15px; background-color: rgb(235, 235, 235);">Random text</div>
    
    Code (markup):
    It would end up as this after being submitted:
    
    <div style="font-size: 15px;">Random text</div>
    
    Code (markup):
    Thanks.
     
    i3urn, Aug 11, 2012 IP
  2. i3urn

    i3urn Member

    Messages:
    238
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    45
    #2
    EDIT:

    Figured it out:
    
    $post = preg_replace("/style=\"(.*?)background-color: rgb\((.*?),(.*?),(.*?)\);(.*?)\"/", "style=\"$1 $5\"", $post);
    
    Code (markup):
     
    i3urn, Aug 11, 2012 IP