Skip to content

Instantly share code, notes, and snippets.

@bran921007
Created January 31, 2015 23:53
Show Gist options
  • Save bran921007/24bbbd4a39df999bc20c to your computer and use it in GitHub Desktop.
Save bran921007/24bbbd4a39df999bc20c to your computer and use it in GitHub Desktop.
Extraer urls con PHP - expresion regular
<?php
$cadena = file_get_contents('http://www.taringa.net');
function extraerURLs($cadena){
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $cadena, $partes);
return ($partes[0]);
}
// Llamamos a la función y le pasamos la cadena a buscar
$urls = extraerURLs($cadena);
// Listamos los resultados
foreach($urls as $url){
echo $url.'<br />';
}
@angelarias
Copy link

por ahi lo use para algo, maybe(?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment