Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
Extracting Data from html using preg_match_all

I have a series of html pages from which I want to extract certain product information. The HTML is build up like this:

<h1 style="margin-top: 20px;">Productinformatie</h1>


<div class="group">
<div class="columns2">
            <table width="100%" cellpadding="4" cellspacing="0" border="0" class="product_info_table stripe">
    <tr style="background-color: #3c75a6; color: #fff; font-weight: bold;">
        <td colspan="2" style="background-color: #3c75a6; border-bottom: 2px solid #9dbeda;">Design</td>
    </tr>
                    <tr class="normal">
            <td width="250" valign="top"><b>Kleur van het product</b></td>
            <td><div style="max-height: 40px; overflow: hidden;">Zwart, Zilver</div></td>
        </tr>
.............
                    <tr class="normal">
            <td width="250" valign="top"><b>Hoogte (achterzijde)</b></td>
            <td><div style="max-height: 40px; overflow: hidden;">3 cm</div></td>
        </tr>
                </table>

</div>  
</div>

<div class="group" style="overflow-x: auto; overflow-y: hidden; height: 140px; white-space: nowrap;" id="image_scroll">

I Use this line but does not get results; I need to find out how Linebrakes (BR) can be formatted in preg_match_all

        //Omschrijving  <h1 style="margin-top: 20px;">Productinformatie</h1>    <div class="group"> <div class="columns2">  </table>    </div>      </div>
//  preg_match_all('/\<h1 style\=\"margin-top\: 20px\;\"\>Productinformatie\<\/h1\>(.*?)\<ul style\=\"list\-style\-type\: none\;\"\>/s', $html, $matchomschrijving);  
    preg_match_all('/\<h1 style\=\"margin-top\: 20px\;\"\>Productinformatie\<\/h1\>(.*)?\<\/table\>.*?\<\/div\>?\<\/div\>/s', $html, $matchomschrijving);  
//  $tempomschrijvinghtml = str_replace('"',"'",$matchomschrijving[1][0]); 
    $tempomschrijvinghtml = MinifyHTML($matchomschrijving[1][0]);
//  $tempomschrijving = '<table>';
    $tempomschrijving .= $tempomschrijvinghtml;
    $tempomschrijving .= '</table></div></div>';
    echo 'Omschrijving: ' . $tempomschrijving . '<br>'; 

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To search, extract and edit html, take advantage of the build-in DOMxxx classes and of the html structure. With the XPath language you can efficiently target the part of the DOM tree you want. Example:

$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$xp = new DOMXPath($dom);

$nodeList = $xp->query('//h1[.="Productinformatie"]/following-sibling::div[@class="group"]/div[@class="columns2"]/table[1]');

echo $dom->saveHTML($nodeList->item(0));
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda