Hi all again.. I'm trying the get at least 3 only cast members from any random movie on IMDB website. This code returns all cast members but also includes what role they played, too much information $name = strip_tags(get_match('#<td class=\"nm\">(.*)<\/td>#',$imdb)); function get_match($regex,$content) { preg_match($regex,$content,$matches); return $matches[1]; } PHP: If I alter the first line to this, $name = strip_tags(get_match('#<td class=\"nm\">(.*)<\/td>#isU',$imdb)); PHP: I get the first actor only which is fine but I'm looking to get the second and third etc... I tried the following but I'm at a loss $name = strip_tags(get_match3('#<td class=\"nm\">(.*)<\/td>#isU',$imdb)); function get_match3($regex,$content) { preg_match($regex,$content,$matches); return $matches[1] . ' ' . $matches[2] . ' ' . $matches[3]; } PHP: It still returns 1 cast member, could someone help me with an example of how to get subsequent results ?
See the notes on preg_match. http://php.net/manual/en/function.preg-match.php "preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match" Use preg_match_all instead. http://www.php.net/manual/en/function.preg-match-all.php
Probable not what you had in mind @lukeg32 but I go it if from this: $actors= strip_tags(get_match3('#<td class=\"nm\">(.*)<\/td>#isU',$imdb)); function get_match3($regex,$content) { preg_match_all($regex,$content,$matches); return $matches[0][0] . '|' . $matches[0][1] . '|' . $matches[0][2]; } PHP: Thanks for pointing me in the ALL direction