【发布时间】:2012-12-23 17:15:56
【问题描述】:
我做了一个简单的应用程序,从allrecipes.com. 等网站获取食谱信息我正在使用preg_match,但有些东西不起作用。
$geturl = file_get_contents("http://allrecipes.com/Recipe/Brown-Sugar-Smokies/Detail.aspx?src=rotd");
preg_match('#<title>(.*) - Allrecipes.com</title>#', $geturl, $match);
$name = $match[1];
echo $name;
我只是想获取页面的标题(减去- Allrecipes.com 部分)并将其放入变量中,但出现的所有内容都是空白的。
【问题讨论】:
-
您是否尝试过打印
$geturl并查看该字符串是否确实存在? -
您无法对代码进行故障排除。例如,在使用返回值之前检查它们。
-
@minitech,是的,当我打印
$geturl时,我得到了整个 Allrecipes.com 页面
标签: php preg-match