i normally use my online web-server for web development, but for some reasons i needed to test it in my XAMPP locally.
my code below will fetch images from a website via curl, and display the total images fetch.
what baffles me, im getting this error on XAMPP:
Notice: Undefined offset: 15 in C:\Web\xampp\htdocs\curl\fetch.php on line 69
line code 69: is if($images_array[$i]) { below
<?php
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $html, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];
?>
<div class="images">
<?php
$k=1;
for ($i=0;$i<=sizeof($images_array);$i++) {
if($images_array[$i]) {
if(strstr($images_array[$i],'http')) {
echo "<img src='".$images_array[$i]."' width='100' id='".$k."' >";
$k++;
}
}
}
?>
<input type="hidden" name="total_images" id="total_images" value="<?php echo --$k?>" />
</div>
i have no problems using this code in my online webserver. i imported all my files from my webserver to XAMPP with no changes made with it. also, my curl is enabled by checking phpinfo()
i hope someone could point whats making this undefined offset error.
var_dump($images_array)orprint_r($images_array)to see what is inside$images_array.error_reportingvalue.