preg_match Cast from IMDB

Discussion in 'PHP' started by MyVodaFone, May 19, 2010.

  1. #1
    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 ?
     
    Last edited: May 19, 2010
    MyVodaFone, May 19, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    lukeg32, May 19, 2010 IP
    MyVodaFone likes this.
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    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 ;)
     
    MyVodaFone, May 19, 2010 IP