Possible en double:
How to extract img src, title and alt from html using php?Impossible d'identifier ce qui est erroné avec mon Regex
Je suis en train d'analyser une page Web et d'obtenir les images complètes. Par exemple,
<html>
<body>
<a href='1.jpg'><img src='tn1.jpg /></a>
<a href='2.jpg'><img src='tn2.jpg /></a>
<a href='3.jpg'><img src='tn3.jpg /></a>
<a href='4.jpg'><img src='tn4.jpg /></a>
</body>
</html>
Je suis en train de les capturer pour obtenir les vignettes complètes qui sont:
1.jpg
2.jpg
3.jpg
4.jpg
Mon code PHP Regex est:
$text = file_get_contents($website); //Get webpage
preg_match_all("~$[0-9](.*?)\.jpg~i", $text, $matches);
Mais quand je le lance, le Le tableau $ matches est vide mais les chemins sont là dans le webiste. Quel pourrait être le problème avec mon Regex?
INFO: Toutes les images suivent un modèle et sont un nombre suivi par .jpg
Cela a été demandé plusieurs fois. Essayez http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php ou http://stackoverflow.com/questions/2120779/regex -php-isolate-src-attribut-de-img-tag ou http://stackoverflow.com/questions/11406453/how-to-get-link-from-img-tag – Oldskool