By Christopher Ambler on Saturday, 17 October 2020
Posted in Technical Issues
Replies 4
Likes 0
Views 685
Votes 0
I am seeing the following warnings:

Notice: Undefined offset: 1 in .../administrator/components/com_easyblog/includes/image/image.php on line 520


preg_match('/src="([^"]+)"/', $image, $src);

$url = $src[1];


In many cases, this preg_match returns no array, so $src is empty. Attempting to index into [1] thus fails. Here's the tag on an image that's not being converted to amp-img. It is found in the outer regex, but not the inner. Could it be that the img tag has a class before the src?


<img class='calloutplanet' src='https://www.retrograde.today/images/planetsretro/mars.png' alt='Mars' />

Hello Christopher,

I have tried to replicate the same image tag in my local and it seems to get the src value correctly:
Editor: https://take.ms/NEXeW
Debug Output: https://take.ms/2XanQ

Can you provide us your backend and FTP access so that we could check the issue on your site?
·
Monday, 19 October 2020 11:20
·
0 Likes
·
0 Votes
·
0 Comments
·
Fails: <img class='calloutplanet' src='https://www.retrograde.today/images/planetsretro/mercury.png' alt='Mercury' />

Succeeds: <img src="https://www.retrograde.today/modules/mod_currentmoon/images/waxing/luna_visible_4.jpg" style="width: 100px; float: left; padding-right: 5px;" alt="moon"/>

Here's your regex: $pattern = '#<img[^>]*>#i';

That matches <img class='calloutplanet' src='https://www.retrograde.today/images/planetsretro/mercury.png' alt='Mercury' /> which is then fed into:

/src="([^"]+)"/

And fails, as it's only looking for double quotes, not single quotes.
·
Monday, 19 October 2020 12:23
·
0 Likes
·
0 Votes
·
0 Comments
·
How about this, instead:

preg_match('/src=["\']([^"]+)["\']/', $image, $src);
·
Monday, 19 October 2020 12:24
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Christopher,

I see. Ya that would help. I will add this in our issue tracker. Thanks.
·
Monday, 19 October 2020 13:47
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post