PHP preg_match_all与正则表达式应用于IMDB演员页面



很难的问题(至少对我来说)希望有人能帮助我,因为我已经得到了很多帮助在这里之前!我有这个代码从iMDB站点获取演员图像

$string = FetchPage($url);
$image_regex_src_url = '/<td id="img_primary"[^>]*'. 'src=["|'](.*)["|']/Ui';
$img_tag_array = $out[0];
$image_regex_src_url = '/<img[^>]*'.'src=["|'](.*)["|']/Ui';
preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
$images_url_array = $out[1];

以Kevin Costner为例:http://www.imdb.com/name/nm0000126/

我试图调整我的代码来获取一个变量到目前为止获得奥斯卡奖的整数从这一行:"赢得2个奥斯卡奖。"和另一个变量他的出生日期从这行"出生:凯文·迈克尔·科斯特纳。1955年1月18日,美国加州林伍德

以这样的结尾:

$actor_oscars = 2;
$actor_birthdate = "January 18, 1955";

问题是,我对正则表达式的了解非常非常有限,我已经尝试过单独做这个(在试错的基础上),完全失败了!有好心人来帮我吗?

PS:我试着把代码放在这里的stackoverflow看起来很漂亮,但即使如此,我似乎没有成功!

提前感谢!

在每个preg_match行之后$matches[1]将包含期望的结果

图像URL:

preg_match( '/<td[^>]*id="img_primary".+?<img[^>]*src="([^"]+)"/s', $str, $matches );

奥斯卡获得:

preg_match( '/Wons(d+)sOscars./', $str, $matches );
出生Month-Day:

preg_match( '/<a href="[^"]*birth_monthday[^"]*">(.+?)</a>/', $str, $matches );
出生年份:

preg_match( '/<a href="[^"]+birth_year[^"]+">(.+?)</a>/', $str, $matches );

最新更新