【发布时间】:2014-07-05 12:50:28
【问题描述】:
我正在尝试提取在 facebook RSS 提要中生成的链接的 PHP,并在单击后将其转换为简单的 html。链接如下所示:
http://l.facebook.com/l.php?u=http%3A%2F%2Fwww.theguardian.com%2Ftravel%2F2014%2Fapr%2F25%2Fitaly-puglia-salento-region&h=2AQF4oNrg&s=1
这是原始链接:
http://www.theguardian.com/travel/2014/apr/25/italy-puglia-salento-region
我正在使用此代码,但第 2 行似乎有错误。
$matches = array();
pregmatchall(/http:\/\/l\.facebook\.com\/l\.php\?u=([^"]+)/, $rss, $matches);
foreach($matches[0] as $index => $match) {
$url = urldecode(html_entity_decode($matches[1][$index]));
str_replace($match, $url, $rss);
}
【问题讨论】:
-
这个看似错误是否带有相关的错误消息?
-
你有语法错误
pregmatchall=>preg_match_all -
@Vijayaragavendran 尝试了下划线,但仍然给出错误:PHP Syntax Check: Parse error: syntax error, unexpected '/', expecting ')' in your code on line 2. 我检查了代码phpcodechecker.com
-
为什么不改用
parse_url,你的目标只是获得?u=的价值 -
试试这个
preg_match_all('/http:\/\/l\.facebook\.com\/l\.php\?u=([^"]+)/', $rss, $matches);