How to select src image using PHP
So, I have several images with several forms:
<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 src image:
$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 this several times, but the code did not work, so please, if anyone has an idea, I will be very grateful.
+1
1 answer
Try this method capture srcfrom imagesrc="([^"]+)"


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);
+2