2014-09-19 2 views
-3

alt 속성을 가져올 정규식이 있습니까? 예 : <img src="http://static.adzerk.net/Advertisers/a61df59863ed44e59446d0b9bb805c56.jpg" title="" alt="blahblah" border="0" height="90" width="728">alt 속성을 가져 오는 정규식

위 이미지 태그에서 "blahblah"를 가져오고 싶습니다.

답변

4

Don't use regexes for parsing HTML

은 테스트되지 않은Demo

$string = '<img src="http://static.adzerk.net/Advertisers/a61df59863ed44e59446d0b9bb805c56.jpg" title="" alt="blahblah" border="0" height="90" width="728">'; 
$dom = new DOMDocument(); 
@$dom->loadHTML($string); 
$anchor = $dom->getElementsByTagName('img')->item(0); 
echo $anchor->getAttribute('alt'); 
+0

내가 대신의 정규식을 필요로하시기 바랍니다. – Michael

+2

@Michael 왜 정규식이어야합니까? –

+0

@ 존콘 확실한 남자는 아무런 문제가 없습니다. 어쨌든 나는 항상이 루트를 선호합니다. – Ghost

관련 문제