SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    remove inline style with preg replace

    hi

    hope i can post preg replace question in this php forum

    i want to replace inline style with preg replace

    PHP Code:
    <?
    $desc 
    '<table style="PADDING-BOTTOM: 0px; BORDER-RIGHT-WIDTH: 0px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; MARGIN: 0px; PADDING-LEFT: 0px; WIDTH: 476px; PADDING-RIGHT: 0px; FONT: 11px/11px Arial, sans-seirf; WHITE-SPACE: normal; ORPHANS: 2; BORDER-BOTTOM-WIDTH: 0px; LETTER-SPACING: normal; COLOR: rgb(0,0,0); VERTICAL-ALIGN: baseline; BORDER-TOP: rgb(227,227,227) 1px solid; BORDER-LEFT-WIDTH: 0px; WORD-SPACING: 0px; PADDING-TOP: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" cellspacing="0">
                <th style="BACKGROUND-IMAGE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 1px; TEXT-TRANSFORM: uppercase; BACKGROUND-COLOR: rgb(246,246,246); MARGIN: 0px; PADDING-LEFT: 6px; WIDTH: 55px; BACKGROUND-ATTACHMENT: scroll; PADDING-RIGHT: 6px; FONT: 13px Oswald; BACKGROUND-POSITION: 0px 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; COLOR: rgb(178,63,51); VERTICAL-ALIGN: top; BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT: medium none; PADDING-TOP: 1px" rowspan="4" scope="row">GENERAL</th>'
    ;
    ?>
    this is my preg code
    PHP Code:
    $full_description preg_replace('/style[^>]*/'''$desc);
    echo 
    $full_description
    But the above preg code remove other attributes like "cellpadding, rowspan, colspan etc"

    i want just to remove the style attribute

    vineet

  2. #2
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    10
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It must like here
    PHP Code:
    $full_description preg_replace('/style=\"[^\"]*/'''$desc); 
    echo 
    $full_description

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    @akalanez ; you forgot the closing " so it will replace style="..." with " instead of removing it altogether.

    PHP Code:
    $full_description preg_replace('/style=\"[^\"]*\"/'''$desc); 
    echo 
    $full_description
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

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

  4. #4
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post

    PHP Code:
    $full_description preg_replace('/style=\"[^\"]*\"/'''$desc); 
    echo 
    $full_description
    thanks scallio

    works perfect

    vineet


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
  •