8791 sujets

Développement web côté serveur, CMS

Bonjour,

Je travaille actuellement sur un site à base Wordpress.

Un petit problème se présente a moi, je cherche a récupéré le href d'un string.
C'est à dire que je récupère via la fonction get_next_posts_link(''); un string du type '<a href="http://localhost:8888/Wordpress/page/2/" ></a>' et je cherche a récupérer 'http://localhost:8888/Wordpress/page/2/'.

J'ai donc cherché à utiliser les RegEx via la fonction preg_replace().

J'ai tenté ceci mais sans résultat :
$next=get_next_posts_link('');
echo $next;
$next=preg_replace('/<a href="([^]+)" ></a>/gi','$1',$next);
echo $next;


Le premier echo fonctionne bien mais le deuxième n'affiche rien. J'ai loupé un truc ?
Modifié par iFef (05 Aug 2011 - 00:05)
Salut,

Il faut utiliser preg_match pour la recherche. Le résultat se trouve dans le tableau passé en paramètre de la fonction.

preg_match('/<a href="([^"]+)">.*?</a>/i',$next,$match));

echo $match[1]; // URL