This is my php function:
$result = file_get_contents('https://www.example.com/index.php');
$regex = '/<img class="pic" src="(.*?)">/';
preg_match($regex, $result, $matches);
return($matches[1]);
it's a function to get a picture from that link, sometimes it return the picture, sometimes not, because the image in the site sometimes take seconde to load sometimes not. I want to prevent that from happening in my function, I want to delay the return until the image is loaded, i know this is not possible with php, sleep() didn't help, so I know that I must do it with javascript, but I don't know how to do it, please help ty!