关于domdocument表的奇怪问题

I have a very weird issue with table cell.

My previous post How to append element to another element using php

My code is like the following

$dom = new DomDocument();
$dom->loadHTML($html]);
$tbodies = $dom->getElementsByTagName('tbody');
foreach ($tbodies as $tbody) {
    $table = $dom->createElement('table');
    $table->setAttribute('width',500);
    $table->setAttribute('style','border:2px solid #8C8C8C;text-align:center;table-layout:fixed; border-collapse:separate;');

     $tbody->parentNode->replaceChild($table, $tbody);
     $table->appendChild($tbody);
 }
$returnText .=$dom->saveHTML();

From my previous pose, I got my answer but it seems like the new html table doesn't have border in the table cell.

So my table like

 ___________
|cell  cell |
|cell  cell |
|___________| 

but I want every cell has border. I am sure my original html table cell has no inline style addressing cell border too.

Can anyone helps?

Thanks!

There is no border on the cells because in css the table tag is styled separately from the cells td or th tag. See here: http://www.quackit.com/html/codes/tables/html_table_border.cfm

edit: Better link.

I have never used domdocument but i see this line :

$table->setAttribute('style','border:2px solid #8C8C8C;text-align:center;table-layout:fixed; border-collapse:separate;');

Instead of adding style attribute that will stylish your table and not td cells , try to add a class for your table that will stylish both table and cells :

$table->setAttribute('class','test');

and add a css file or a style that containts your class :

 <style type='text/css'>

    .test{
       border:2px solid #8C8C8C;
       text-align:center;
       table-layout:fixed;
       border-collapse:separate;
     }

    .test th,.test td{border:2px solid #8C8C8C;}
 </style>