jeudi 30 juin 2016

PHP Dom Document - Using Glob and get and specific element and class in every file of a directory

I'm using Glob function in order to get every .htm file and then I trying to get text from a specific table where class = 'DataGrid_Item', by using PHP's DOM element with following HTML (same structure) and following code:

1. HTML

<div>
<table rules="all" id="GridViewAfiliacion" style="border-collapse:collapse;" border="1" cellspacing="0">
    <tbody>
        <tr class="DataGrid_Header" style="background-color:#98B676;">
            <th scope="col">ESTADO</th>
            <th scope="col">ENTIDAD</th>
            <th scope="col">REGIMEN</th>
            <th scope="col">FECHA DE AFILIACION ENTIDAD</th>
            <th scope="col">TIPO DE AFILIADO</th>
        </tr>
        <tr class="DataGrid_Item" align="center">
            <td>ACTIVO</td>
            <td>NUEVA EPS S.A.</td>
            <td>CONTRIBUTIVO</td>
            <td>01/06/2016</td>
            <td>COTIZANTE</td>
        </tr>
    </tbody>
</table>

2. PHP

    // Directory of Files

$directory = "../fosyga/archivoshtml/";
$array_filename = glob($directory . "*.htm");

foreach($array_filename as $filename)
    {
    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->loadHTML($filename);
    $content_node = $dom->getElementById("GridViewAfiliacion");

    // Get the HTML as a string

    $string = $content_node > C14N();
    }

It's possyble to extract class="DataGrid_Item" info into a string?

Pd: I think the glob function does not work properly in this case, I'm not using that in a correct way.

Aucun commentaire:

Enregistrer un commentaire