Pregunta

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

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top