PHP: How to use preg_match_all in this section?

1

Site I want to get the data

I need to use preg_match_all to get what's inside

<table class="grid-table survey-info" cellspacing="0">

For the moment I did the following

<?php

$url = 'http://metadados.capes.gov.br/index.php/catalog/100';


$dadosSite = file_get_contents($url);

preg_match_all('/(O que falta)/', $dadosSite, $conteudo);

$echo conteudo[0][0];
?>
    
asked by anonymous 21.11.2017 / 17:54

1 answer

0

I used the tags in the table to give a way to output, example replacing <td class="label"> with Label : and so on. But these td class="value" are all cluttered, have <td class="value"> and <td class="value" > etc

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<?php
$myLine = "";
if(!($myFile=fopen("http://metadados.capes.gov.br/index.php/catalog/100","r"
)))
{
echo "Arquivo não-acessível";
exit;
}
while(!feof($myFile))
{
$myLine .= fgets($myFile,255);
}
fclose($myFile);

$start = '<table class="grid-table survey-info" cellspacing="0">'; //ponto inicial da procura no código fonte da pg
$end = "</table>"; //ponto final da procura no código fonte da pg
$start_position=strpos($myLine, $start);
$end_position=strpos($myLine, $end)+strlen($end);
$length = $end_position - $start_position;
$myLine = substr($myLine, $start_position, $length);

$myLine = str_replace('<table class="grid-table survey-info" cellspacing="0">',"",$myLine);

$myLine = str_replace('</table>',"",$myLine);

$myLine = str_replace('<tr>',"",$myLine);
$myLine = str_replace('</tr>',"<br>",$myLine);

$myLine = str_replace('<tr valign="top"  >',"",$myLine);

$myLine = str_replace('<tr itemprop="spatial" itemscope="itemscope" itemtype="http://schema.org/Country">',"",$myLine);

$myLine = str_replace('<tr valign="top" itemprop="producer" itemscope="itemscope" itemtype="http://schema.org/Person">',"",$myLine);

$myLine = str_replace('<td class="value links">',"",$myLine);

$myLine = str_replace('<td class="label">',"Label: ",$myLine);

$myLine = str_replace('<td class="value">',"Valor: ",$myLine);

$myLine = str_replace('<td class="value" itemprop="temporal">',"Valor: ",$myLine);

$myLine = str_replace('<td class="value"  itemprop="name">',"Valor: ",$myLine);

$myLine = str_replace('<td class="value" itemprop="name" >',"Valor: ",$myLine);

$myLine = str_replace('<td class="value" >',"Valor: ",$myLine);

$myLine = str_replace('</td>',"",$myLine);

$myLine = preg_replace(array("/\t/", "/\s{2,}/", "/\n/", "/\r/"), array("", " ", " ", " "), $myLine);

echo $myLine;

?>
    
21.11.2017 / 19:59