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. Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.