Bonjour,
Comment faire pour récupérer une chaine comprise entre le dernier "/" et le ".html" d'une url ?
Version imprimable
Bonjour,
Comment faire pour récupérer une chaine comprise entre le dernier "/" et le ".html" d'une url ?
Bonjour,
faudra la mettre en FAQ celle-là :roll:
Code:$reg = '#http://.*/(.+)\.html(?:\?.*)#';
heuuuuu, c'est a dire, ..., comment fait on pour l'utiliser ?
c'est obscure pour moi.
Au temps pour moi, je te donne un code pour tester
et la page de manuel qui va bien : http://www.php.net/manual/fr/function.preg-match.phpCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <?php $reg = '#http://.*/(.+)\.html(?:\?.*)?#'; $str = 'http://monurl.fr/foobar.html'; preg_match($reg, $str, $match); print_r($match); // renvoie foobar $str = 'http://monurl.fr/foobar.html?param=truc'; preg_match($reg, $str, $match); print_r($match); // renvoie foobar $str = 'http://monurl.fr'; preg_match($reg, $str, $match); print_r($match); // ne renvoie rien
Avec mes sinceres remerciement