问题
So i have some images with several forms like this :
<a href="" class="link-img" alt="">
<img editable="true" style="display: block; cursor: default;" class="main-image"
width="538" height="auto" src="src" alt="large image">
</a>
and like this :
<a href="" class="link link-img">
<img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true"
class="main-image imageLink" width="" height="auto" alt="">
</a>
so my code to select the src image is :
$c = preg_replace('/<a href="(.+)" class="link link-img" alt="(.+)"><img src="(.+)"><\/a>/i'
,'<% link url="$1" caption="<img style=max-width:500px; src=$8 >" html="true" %>',$c);
i tried that several times but the code doesn't worked, so please if someone has any idea i will be very appreciative.
回答1:
Try this way to grab src
from image src="([^"]+)"
EDIT : see regex here https://www.regex101.com/r/yF8tJ1/1
CODE EXAMPLE:
$re = "/src=\"([^\"]+)\"/";
$str = "<a href=\"\" class=\"link-img\" alt=\"\">\n <img editable=\"true\" style=\"display: block; cursor: default;\" class=\"main-image\" \n width=\"538\" height=\"auto\" src=\"src\" alt=\"large image\">\n</a>\n\n<a href=\"\" class=\"link link-img\">\n <img src=\"src\" style=\"width: 100%; display: block; cursor: pointer;\" editable=\"true\" \n class=\"main-image imageLink\" width=\"\" height=\"auto\" alt=\"\">\n</a>";
preg_match_all($re, $str, $matches);
来源:https://stackoverflow.com/questions/27988667/how-to-select-image-src-using-php