SitePoint Sponsor

User Tag List

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

    Remove inline styles dynamically

    hi all

    below is the content of "$detail"


    i want to remove all inline styles from inside the <tr><th><td> etc tags dynamically

    while displaying

    PHP Code:
    <tr style="PADDING-BOTTOM: 0px; BORDER-RIGHT-WIDTH: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; FONT-SIZE: 11px; VERTICAL-ALIGN: baseline; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px; border-image: initial">
                <
    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; background-origin:initial; background-clip: initial; border-image: initial" rowspan="4" 
    scope="row">GENERAL</th>
                <
    td style="BACKGROUND-IMAGE: none; BORDER-BOTTOM: rgb(240,240,240) 1px solid; PADDING-BOTTOM: 1px; BORDER-RIGHT-WIDTH: 0px; BACKGROUND-COLOR: rgb(250,250,250); MARGIN: 0px; PADDING-LEFT: 6px; WIDTH: 77px; BACKGROUND-ATTACHMENT: scroll; PADDING-RIGHT: 6px; FONT: bold 12px/16px Arial; BACKGROUND-POSITION: 0px 0px; BORDER-TOP-WIDTH: 0px; COLOR: rgb(125,116,100); VERTICAL-ALIGN: top; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 1px; background-origin: initial; background-clip: initial; border-image: initial" class="ttl"><font color="#7d7464">Network</font></td>
                <
    td style="BACKGROUND-IMAGE: none; BORDER-BOTTOM: rgb(240,240,240) 1px solid; PADDING-BOTTOM: 1px; BORDER-RIGHT-WIDTH: 0px; BACKGROUND-COLOR: rgb(250,250,250); MARGIN: 0px; PADDING-LEFT: 6px; BACKGROUND-ATTACHMENT: scroll; PADDING-RIGHT: 6px; FONT: 12px/16px Arial; BACKGROUND-POSITION: 0px 0px; BORDER-TOP-WIDTH: 0px; VERTICAL-ALIGN: top; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 1px; background-origin: initial; background-clip: initial; border-image: initial" 
    class="nfo">GSM 850 900 1800 1900</td>
            </
    tr
    should display like
    PHP Code:
    <tr>
    <
    th>general</th>
    <
    td>network</td>
    <
    td>gsm 850/900</td>
    </
    tr
    vineet

  2. #2
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i googled it and found this solution

    PHP Code:
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $search = new DOMXPath($doc);
    $results $search->evaluate('//*[@style]');
    foreach (
    $results as $result)
        
    $result->removeAttribute('style');
    $newhtml $doc->saveHTML();
    echo 
    $newhtml 
    When i implement it, i get 2 <html> starting

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>Untitled Document</title>
    </
    head>
    <
    body>
    here is the second doctyle starts
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <
    html><body><table><tbody><tr>
    <
    th rowspan="4" scope="row">GENERAL</th>
                <
    td class="ttl"><font color="#7d7464">2G Network</font></td>

                <
    td class="nfo">GSM 850 900 1800 1900</td>
            </
    tr></tbody></table></body></html>
    </
    body>
    </
    html
    can anyone tell me how to use the above solution

    vineet

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Vineet,

    Does this need to be done using PHP as Javascript is a good candidate to do this?

    Steve
    ictus==""


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
  •