【发布时间】:2011-02-11 20:17:43
【问题描述】:
我真的对 PHP 的正则表达式感到困惑。
无论如何,我现在无法阅读整个教程,因为我有一堆 html 文件,我必须尽快在其中找到链接。我想出了用我知道的语言的 php 代码来自动化它的想法。
所以我想我可以使用这个脚本:
$address = "file.txt";
$input = @file_get_contents($address) or die("Could not access file: $address");
$regexp = "??????????";
if(preg_match_all("/$regexp/siU", $input, $matches)) {
// $matches[2] = array of link addresses
// $matches[3] = array of link text - including HTML code
}
我的问题是$regexp
我需要的模式是这样的:
href="/content/r807215r37l86637/fulltext.pdf" title="Download PDF
我想从上面的行中搜索并获取/content/r807215r37l86637/fulltext.pdf,我在文件中有很多。
有什么帮助吗?
===================
编辑
标题属性对我来说很重要,我想要的所有属性都有标题
title="下载 PDF"
【问题讨论】: