Jump to content

iknowthatimnoobphp

New Members
  • Posts

    3
  • Joined

  • Last visited

iknowthatimnoobphp's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yea, you are right. I can't do this on regex. I'm tied of this My code is more complicated. Input code: <table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#ffffff"> <tbody> <tr> <td style="padding: 0px; text-align: left;"> <table class="class-table-1" width="42%" cellspacing="0" cellpadding="0" border="0" align="right" style="max-width: 250px;"> <tbody> <tr> <td align="right" valign="top"><img src="image1.jpg" /></td> </tr> <tr> <td align="left">Lorem Ipsum</td> </tr> </tbody> </table> <table class="class-table-2" width="56%" cellspacing="0" cellpadding="0" border="0" align="left" style="max-width: 325px;"> <tbody> <tr> <td align="left"><img src="image2.jpg" /></td> </tr> </tbody> </table> </td> </tr> <tr> <td align="center" valign="top"><img src="image3.gif" /></td> </tr> </tbody> </table> I want to get tables [class=class-table-1" width="42%] and [class=class-table-2" width="56%] and insert into new table cells Output code: <table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#ffffff"> <tbody> <tr> <td style="padding: 0px; text-align: left;"> <table dir="rtl"><tr><td width="250" align="right"> //<-- INSERTED <table class="class-table-1" width="42%" cellspacing="0" cellpadding="0" border="0" align="right" style="max-width: 250px;"> <tbody> <tr> <td align="right" valign="top"><img src="image1.jpg" /></td> </tr> <tr> <td align="left">Lorem Ipsum</td> </tr> </tbody> </table> </td><td width="330" align="left"> //<-- INSERTED <table class="class-table-2" width="56%" cellspacing="0" cellpadding="0" border="0" align="left" style="max-width: 325px;"> <tbody> <tr> <td align="left"><img src="image2.jpg" /></td> </tr> </tbody> </table> </td><tr></table> //<-- INSERTED </td> </tr> <tr> <td align="center" valign="top"><img src="image3.gif" /></td> </tr> </tbody> </table> I don't know how do this with simpleHTMLDOM
  2. Hello, I need get from HTML code tables with specific class and width attribute and insert it into the div element. How do this with preg_replace? The following example shows what I want to do. Input Code: <table class="some-class" width="30%" cellspacing="0" cellpadding="0" border="0" style="color:red""> <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> <table class="some-class" cellspacing="0" cellpadding="0" border="0" width="100%" > <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> <table cellspacing="0" cellpadding="0" border="0" width="30%" class="some-class" > <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> Get tables with class= "some-class" and width="30%" and put it to the <div>. The order of the attributes table is not fixed and may be different (random). Output Code: <div> <table class="some-class" width="30%" cellspacing="0" cellpadding="0" border="0" style="color:red""> <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> </div> <table class="some-class" cellspacing="0" cellpadding="0" border="0" width="100%" > // does not insert to div because another attribute width <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> <div> <table cellspacing="0" cellpadding="0" border="0" width="30%" class="some-class" > <tbody> <tr><td><img src="picture.jpg" /></td></tr> <tr><td>Lorem ipsum dolor sit amet</td></tr> </tbody> </table> </div> Of course, the sample code is highly simplified. Tables can be included in other tables or HTML elements.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.