Per primo dovresti toglierere quella chiocciola dalla funzione getimagesize, dato che sopprime gli errori... E per secondo dovresti provare ad inserire error_reporting(E_ALL) all'inizio dello script in modo da visualizzare tutti gli errori.
Codice PHP:
<?php
error_reporting(E_ALL);
$commento="parte iniziale <img src=http://pics.hoobly.com/full/6YJTJ1BVN7KYFNSFX5.jpg alt=image> parte finale";
function check_img($stringa,$width_max,$height_max){
if(strstr($stringa,"alt=image>")){ //se nel messaggio c'è un'immagine
$stringa_exp = explode("alt=image>",$stringa); //suddividi il messaggio quando trovi "alt=image>"
while(list($i,$item) = each($stringa_exp)){
//L'ultima stringa non deve essere processata ma direttamente inserita per l'uscita
if($i == count($stringa_exp)-1){
$stringa2 .= $item;
break;
}
$inizio = strpos(rtrim($item), "<img src=");//trova la posizione di "<img src="
//vengono estratti tutti i link di immagini presenti nel messaggio. Il 9 è dovuto ai caratteri costituenti "<img src="
$stringa1 = rtrim(substr($item,($inizio+9)));
$img = getimagesize('$stringa1'); //estrae le dimensioni di ogni immagine
if($img[0] > $width_max || $img[1] > $height_max){
$end_tag = "<img width=".$width_max." height=".$height_max." src=";
}else $end_tag = "<img src=";
$stringa2 .= str_replace("<img src=",$end_tag,$item." alt=image>");
}
}else $stringa2 = $stringa;
$vettore = array($stringa2,$stringa1,$img[0],$img[1]);
return $vettore[2];
}
$commento=check_img($commento,300,300);
echo $commento;
?>
Comunque non so se conosci le espressioni regolari, ti risparmi tutto quel lavoro che fai con explode e strpos...