06/09/2013, 09:58
|
| | | Fecha de Ingreso: junio-2012
Mensajes: 24
Antigüedad: 12 años, 5 meses Puntos: 0 | |
Respuesta: Escapar string para preg_match
Código:
<?php
//YOUTUBE INTEL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com/user/channelintel');
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);
//GUARDAR PAGINA
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
//PARSEAR
$regex = '/<span class="yt-subscription-button-subscriber-count-branded-horizontal subscribed">(.*)<\/span>/';
preg_match_all($regex, $result, $matches);
$suscriptores = $matches[1][0]; //LINEA 22
echo "Suscriptores: " . $suscriptores;
?>
El error que salta es:
Código:
Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/curl1.php on line 22
|