我试图从preg匹配中获取一个链接,但它没有提供任何输出
这是模式:
<a href="http://media1.xyz.com/full5/Animals/Rabbits/rabbits-16a.jpg" download="rabbits-16a"><img onmouseover="showFullScreen('inline')" onmouseout="showFullScreen('none')" src="http://media1.xyz.com/full5/Animals/Rabbits/rabbits-16a.jpg" id="wall" border="0" align="middle" width="1920" height="1080" alt="Rabbits 1920x1080 Wallpaper # 17" title="Rabbits HD Wallpaper #17" /></a>
我试过这个:
preg_match("/\<a href=/\"(.*)\">/",$str,$title);
我想获得href的链接。
答案 0 :(得分:0)
使用此匹配模式应该可以正常工作
'/href=\"(.*?)\"/s'
我用它来匹配我正在从IMAP电子邮件中解析的图像标签中的来源(原始形式'/src=\"(.*?)\"/s'
但只是将src更改为href将匹配你
答案 1 :(得分:0)
$input = '<a href="http://media1.xyz.com/full5/Animals/Rabbits/rabbits-16a.jpg" download="rabbits-16a"><img onmouseover="showFullScreen(\'inline\')" onmouseout="showFullScreen(\'none\')" src="http://media1.xyz.com/full5/Animals/Rabbits/rabbits-16a.jpg" id="wall" border="0" align="middle" width="1920" height="1080" alt="Rabbits 1920x1080 Wallpaper # 17" title="Rabbits HD Wallpaper #17" /></a>';
preg_match('/href=\"(.+?)\"/',$input,$title);
echo $title[1];
将输出:
http://media1.xyz.com/full5/Animals/Rabbits/rabbits-16a.jpg