par
BaLiSTiK » 29 juin 2006, 10:41
bjr, j ai une fonction qui permet d extraire des liens compris entre les balises <A href> et </A> se trouvant dans une base de donnée, ça marche nickel sauf à un detail pres. Elle n extrait que les lien compris entre <A href="url">balbla</A> et non avec <a href="url">blabla</a>
la fonction :
function getHrefLinks($content) {
$motif='`<A href="[^>]+">[^<]+</A>`';
preg_match_all($motif,$content,$out);
$motif='`href="[^>]+"`';
$out3 = array();
foreach ($out[0] as $value) {
preg_match_all($motif,$value,$out2);
if (count($out2)>0) {
$thisString = $out2[0][0];
$thisString = str_replace("\"", "", $thisString);
$thisString = str_replace("href=", "", $thisString);
$thisString2 = split (" ", $thisString);
$thisString = $thisString2[0];
if (substr($thisString, 0,strlen("http://"))!="http://") {
$urlParsed = parse_url($_SERVER["PHP_SELF"]);
$path_parts = pathinfo($urlParsed["path"]);
$thisString = "http://".$_SERVER["HTTP_HOST"].$path_parts["dirname"].$thisString;
}
$out3[] = $thisString;
}
}
return $out3;
}
je voudrais eviter de faire une deuxieme fonction qui contiendrait
$motif='`<a href="[^>]+">[^<]+</a>`';
Y a t'il un moyen de concatener ou alors opter pour la solution d une fonction getHrefLinks2 qui extrait les lien dont les balises sont en minuscule?
bjr, j ai une fonction qui permet d extraire des liens compris entre les balises <A href> et </A> se trouvant dans une base de donnée, ça marche nickel sauf à un detail pres. Elle n extrait que les lien compris entre <A href="url">balbla</A> et non avec <a href="url">blabla</a>
la fonction :
[php]
function getHrefLinks($content) {
$motif='`<A href="[^>]+">[^<]+</A>`';
preg_match_all($motif,$content,$out);
$motif='`href="[^>]+"`';
$out3 = array();
foreach ($out[0] as $value) {
preg_match_all($motif,$value,$out2);
if (count($out2)>0) {
$thisString = $out2[0][0];
$thisString = str_replace("\"", "", $thisString);
$thisString = str_replace("href=", "", $thisString);
$thisString2 = split (" ", $thisString);
$thisString = $thisString2[0];
if (substr($thisString, 0,strlen("http://"))!="http://") {
$urlParsed = parse_url($_SERVER["PHP_SELF"]);
$path_parts = pathinfo($urlParsed["path"]);
$thisString = "http://".$_SERVER["HTTP_HOST"].$path_parts["dirname"].$thisString;
}
$out3[] = $thisString;
}
}
return $out3;
}
[/php]
je voudrais eviter de faire une deuxieme fonction qui contiendrait
[php]
$motif='`<a href="[^>]+">[^<]+</a>`';
[/php]
Y a t'il un moyen de concatener ou alors opter pour la solution d une fonction getHrefLinks2 qui extrait les lien dont les balises sont en minuscule?