par
gdc » 04 févr. 2013, 11:13
Salut,
utiliser la petite RegEx qui va bien :
<?php
$str = '
<p><a href="http://php-france.com">du texte</a> du texte <a href="http://php.net">du texte</a></p>
<p><a href="http://www.google.com">du texte</a> du texte <a href="http://www.yahoo.fr">du texte</a></p>
';
$motif = '#href="(.+)"#U';
preg_match_all($motif,$str,$match);
echo '<pre>';
print_r($match);
echo '</pre>';
MERCI ca fonction a trop
Le seul probleme c'est que ca me retourne trop de fois le meme texte:
resultat dans ma page:
Array ( [0] => Array ( [0] => href="http://www.LE_LIEN/?sub=test" ) [1] => Array ( [0] => http://www.LE_LIEN/?sub=test) )
il y en as une avec les " et l'autre sans les " ??
pouvez vous m'éclaircir SVP
Voila ma function :
function test(){
$query = mysql_query("SELECT html FROM MA_TABLE WHERE id_pub = '12345' ");
$res = mysql_fetch_array($query);
$str = $res['html'];
$motif = '#href="(.+)"#U';
preg_match_all($motif,$str,$match);
print_r ($match);
}
MERCI ....
[quote="niuxe"]Salut,
utiliser la petite RegEx qui va bien :
[php]
<?php
$str = '
<p><a href="http://php-france.com">du texte</a> du texte <a href="http://php.net">du texte</a></p>
<p><a href="http://www.google.com">du texte</a> du texte <a href="http://www.yahoo.fr">du texte</a></p>
';
$motif = '#href="(.+)"#U';
preg_match_all($motif,$str,$match);
echo '<pre>';
print_r($match);
echo '</pre>';
[/php][/quote]
MERCI ca fonction a trop :)
Le seul probleme c'est que ca me retourne trop de fois le meme texte:
resultat dans ma page:
Array ( [0] => Array ( [0] => href="http://www.LE_LIEN/?sub=test" ) [1] => Array ( [0] => http://www.LE_LIEN/?sub=test) )
il y en as une avec les " et l'autre sans les " ??
pouvez vous m'éclaircir SVP
Voila ma function :
[php]function test(){
$query = mysql_query("SELECT html FROM MA_TABLE WHERE id_pub = '12345' ");
$res = mysql_fetch_array($query);
$str = $res['html'];
$motif = '#href="(.+)"#U';
preg_match_all($motif,$str,$match);
print_r ($match);
}[/php]
MERCI ....