How to return a part of a string (an html element) in php?

3

I am making a "technical resource" to be able to return the status of the SEFAZ servers issuing invoices using PHP. For this, I have so far the code below:

function get_content($URL){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $URL);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$d = get_content('http://www.nfe.fazenda.gov.br/portal/disponibilidade.aspx');
echo $d;

This code returns me the page that the recipe makes available without needing a digital certificate to see the status of the servers.

I need to know how I can do to get only an existing HTML element within the $d variable (the element is table.tabelaListagemDados ) and from its values I can do treatments.

I know that I can handle this information using javascript (pure, with AngularJS or with jQuery) but if there is any method through PHP it is better because I can return only one JSON and not a whole page. >

Does anyone see a solution on how I can do to get only this element within the page?

    
asked by anonymous 23.12.2015 / 03:15

2 answers

3

See if this helps you:

$data = get_content('http://www.nfe.fazenda.gov.br/portal/disponibilidade.aspx');
$dom = new domDocument;
@$dom->loadHTML($data);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item(1)->getElementsByTagName('tr');

foreach ($rows as $row) {
        $cols = $row->getElementsByTagName('td');
        print_r($cols);
}
    
23.12.2015 / 16:06
1

Talk, guys, I've been able to solve my problem. Below is the script that takes the page that shows the availability of electronic invoice sending webservices and transforms the content into a json.

link

If you want to use it, please feel free, but please leave credits.

    
23.12.2015 / 17:49