使用正则表达式或 HTML 解析器查找所有以 pdf 文件作为 PHP 源代码的锚标记


finding all anchor tags with pdf file as the source in php using regex or HTML parser

如何使用源pdf找到所有anchor标签

$string="hello this is a dummy text <a href="../../abc.pdf"> 

我只需要在字符串变量中abc.pdf

你应该使用 DOMDocument 而不是正则表达式:

$string='hello this is a dummy text <a href="../../abc.pdf">'; 
$doc = new DOMDocument;
$doc->loadHTML($string);
$href = $doc->getElementsByTagName('a')->item(0)->getAttribute('href');
echo basename($href); // abc.pdf