xsubs Posted October 26, 2007 Share Posted October 26, 2007 I'm trying to get GENRE from IMDB.com. I made this code: <?php $site = file_get_contents('http://www.imdb.com/title/tt0458522'); // Genre finding preg_match_all("/<a href=\"\/Sections\/Genres\/(.*?)\/\">/si" , $site , $GenreArr); $SizeoGenre = sizeof($GenreArr[1]); echo $SizeoGenre; $Genre = ""; for ($i=0;$i<=$SizeoGenre;$i++) { $Genre .= $GenreArr[1][$i]; if ($i !== $SizeoGenre) { $Genre .= " / "; } } ?> But it returns Biography / Drama / Music / (The problem is that it returns wrong number of "/" signs) What can i do to solve this? Is there another better way to to it? Thanks. Link to comment https://forums.phpfreaks.com/topic/74878-problem-with-preg_match_all/ Share on other sites More sharing options...
effigy Posted October 26, 2007 Share Posted October 26, 2007 <pre> <?php $site = file_get_contents('http://www.imdb.com/title/tt0458522'); preg_match_all('#(?<=<a href="/Sections/Genres/)([^">/]+)#i' , $site , $genres); $genres = $genres[1]; print implode(' / ', $genres); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/74878-problem-with-preg_match_all/#findComment-378561 Share on other sites More sharing options...
xsubs Posted October 26, 2007 Author Share Posted October 26, 2007 What is all the signs you added? can you explain to me? Thanks. Link to comment https://forums.phpfreaks.com/topic/74878-problem-with-preg_match_all/#findComment-378565 Share on other sites More sharing options...
effigy Posted October 26, 2007 Share Posted October 26, 2007 (?<=<a href="/Sections/Genres/)--A positive lookbehind. ([^">/]+)--Capture 1 or more characters, excluding double quotes, right angle brackets, and forward slashes. Link to comment https://forums.phpfreaks.com/topic/74878-problem-with-preg_match_all/#findComment-378590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.