-2

我正在尝试从预赛中获取链接,但它没有提供任何输出

这是模式:

    <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的链接。

4

2 回答 2

-1

使用此匹配模式应该可以工作

'/href=\"(.*?)\"/s'

我用它来匹配我从 IMAP 电子邮件解析的图像标签中的源(以其原始形式'/src=\"(.*?)\"/s' 但只需将 src 更改为 href 即可匹配您

于 2013-10-14T12:47:28.543 回答
-1
$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

http://3v4l.org/QnJ9e

于 2013-10-14T12:52:05.880 回答