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

StackOverflow https://stackoverflow.com/questions/10991395

  •  13-06-2021
  •  | 
  •  

Вопрос

how can i find all the anchor tags with source pdf

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

i need only abc.pdf in the string variable

Это было полезно?

Решение

You should use DOMDocument instead of regex:

$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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top