Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Extrayendo datos de html usando preg_match_all

Tengo una serie de páginas html de las que quiero extraer cierta información del producto. El HTML se construye así:

 <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">

Uso esta línea pero no obtengo resultados; Necesito averiguar cómo se pueden formatear Linebrakes (BR) en 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>';

Gracias.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Para buscar, extraer y editar html, aproveche las clases DOMxxx integradas y la estructura html. Con el lenguaje XPath, puede apuntar de manera eficiente a la parte del árbol DOM que desee. Ejemplo:

 $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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda