please help me. i got error log after upgrade php from 7.4 to 8.1 :
PHP Warning: Undefined array key 0
this is the script code, please help me, how to fix this
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*?>/i', $post->post_content, $matches);
$tanpahttp = array("http://","https://");
$gambar1 = $matches[1][0];
$gambar2 = str_replace($tanpahttp,"",$matches[1][0]);
$first_img = $gambar2;
if(empty($first_img)) {
$first_img = "https://kbimages.dreamhosters.com/images/Site_Not_Found_Dreambot.fw.png";
}
return $first_img;
}
it fine in 7.4 but i must upgrade mine
im very confused, im was weak from this coding for php 8.1
but if i running in 7.4 my site is fine, in php8.0 it error log very long and my cpu is spike high. i just want to grab image from my first image in my wordpress site become my feature post thumbnail