par
Cyrano » 30 déc. 2005, 12:20
Avec une petite modification et une correction dans l'expression, oui :
<?php
$chaine = "coucou http://www.site.com?var=truc&machin=Kool plouf f http://www.caca.fr ffff http://elie.najberg.fr fffffff";
$masque = "#(?:(?:(?:https?|ftp)://)?(?:www\.)?\w+(?:(?:/|\.)\w+)*\.\w{2,4})(?:\?\w+=\w+(?:\&\w+=\w+)*)?#i";
preg_match_all($masque, $chaine, $sortie);
?>
<pre>
<?php
print_r($sortie);
?>
</pre>
Va afficher:
Code : Tout sélectionner
Array
(
[0] => Array
(
[0] => http://www.site.com?var=truc&machin=Kool
[1] => http://www.caca.fr
[2] => http://elie.najberg.fr
)
)
Avec une petite modification et une correction dans l'expression, oui :
[php]<?php
$chaine = "coucou http://www.site.com?var=truc&machin=Kool plouf f http://www.caca.fr ffff http://elie.najberg.fr fffffff";
$masque = "#(?:(?:(?:https?|ftp)://)?(?:www\.)?\w+(?:(?:/|\.)\w+)*\.\w{2,4})(?:\?\w+=\w+(?:\&\w+=\w+)*)?#i";
preg_match_all($masque, $chaine, $sortie);
?>
<pre>
<?php
print_r($sortie);
?>
</pre>[/php]
Va afficher:
[code]Array
(
[0] => Array
(
[0] => http://www.site.com?var=truc&machin=Kool
[1] => http://www.caca.fr
[2] => http://elie.najberg.fr
)
)[/code]