【发布时间】:2011-12-01 15:56:01
【问题描述】:
我正在尝试遍历链接数组,并使用 file_get_contents 获取源代码并从中获取某些内容:
$links = file('mysite2.txt');
foreach($links as $link) {
$f = file_get_contents("$link");
$source = $f;
if(preg_match('/<meta pro=\"(.*)\" \/>/',$source,$matches)) {
$answer = $matches[1];
echo "$answer";
}
}
现在,当我在 file_get_contents (file_get_contents("$link")) 函数中使用 $link 时,preg_match 条件为假。然而,当我在file_get_contents (`file_get_contents("http://www.site.com/something")) 中使用 my_site2.txt 中的链接之一时,它可以正常工作。
我什至尝试过使用仅包含一个链接的不同 txt 文件,该链接在源代码中具有正确的字符串。
我也试过不带引号:file_get_contents($link)
【问题讨论】:
标签: php file-get-contents