문제

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