jhonlozanot Seguir
VIP
Eta
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Suscripción a IA
- Desde
- 19 Feb 2013
- Mensajes
- 1.441
Soy nuevo en esto de php y estoy practicando parsear html, ojala alguien me pueda ayudar la verdad soy nobato, explico lo que quiero lograr.
Este es mi codigo html donde el cual quiero sacar datos especificos el cual es el nombre y apellidos.
Y este es mi codigo php con el cual quiero parsear los datos:
Me tira el siguiente error:
Este es mi codigo html donde el cual quiero sacar datos especificos el cual es el nombre y apellidos.
HTML:
<td width="35%">Apellido paterno</td>
<td style="background-color: white">OSORIO </td>
</tr>
<tr>
<td width="35%">Apellido materno</td>
<td style="background-color: white">MENDOZA </td>
</tr>
<tr>
<td width="35%">Nombres</td>
<td style="background-color: white">PEPE </td>
Y este es mi codigo php con el cual quiero parsear los datos:
PHP:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'localhost/bot/index.php');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
//Parsear
preg_match_all("(<td width=\"35%\">Apellido paterno</td> <td style=\"background-color: white\">(.*)</td>)siU", $result, $matches1);
preg_match_all("(<td width=\"35%\">Nombre materno</td> <td style=\"background-color: white\">(.*)</td>)siU", $result, $matches2);
preg_match_all("(<td width=\"35%\">Nombres</td> <td style=\"background-color: white\">(.*)</td>)siU", $result, $matches3);
$appaterno = $matches1[1][0];
$apmaterno = $matches2[1][0];
$nombres = $matches2[1][0];
?>
<style>
.container
{
background: white;
font-family: Helvetica;
font-size: 19px;
border-radius: 1em;
box-shadow: 0px 5px 5px rgba(0,0,0,0.5);
margin: 1em auto;
padding: 1em;
width: 25%;
}
</style>
<div class="container">
<?="Datos de Persona:</br>"?>
<?="Apellido Paterno: <b>" . $appaterno.'</b>'?>
<?="Apellido Materno: <b>" . $apmaterno.'</b>'?>
<?="Nombre: <b>" . $nombres.'</b>'?>
</div>
Me tira el siguiente error:
Insertar CODE, HTML o PHP:
Notice: Undefined offset: 0 in C:\xampp\htdocs\bot\bot.php on line 18
Notice: Undefined offset: 0 in C:\xampp\htdocs\bot\bot.php on line 19
Notice: Undefined offset: 0 in C:\xampp\htdocs\bot\bot.php on line 20