coolbyte Posted May 10, 2011 Report Posted May 10, 2011 Buna ziua.Am urmatorul script:<php> $inlocuit = array("http://", "ftp://"); $link1 = str_replace($inlocuit, "", $linkdown); $host = substr($link1, 0, strpos($link1, "/")); $path = strstr($link1, '/'); $port = 80; $content_length = 0; $fp = fsockopen($host, $port); fputs($fp, "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"); while (% aici am pus @%"\r\n\r\n" != ($line = fgets($fp, 1024))) { if (preg_match("/content-length: (\d+)/i", $line, $match)) { $content_length = $match[1]; break; } } fclose($fp); $size = $content_length; $sizeKB=$size/1024; if ($sizeKB >1024){ $sizeMB=$sizeKB/1024; if ($sizeMB>1024){ $sizemb=$sizeMB/1024; } else{ $sizeMB = round($sizeMB,2); echo "$sizeMB MB"; } } else{ $sizeKB = round($sizeKB,2); echo "$sizeKB KB"; } <php>In momentul in care nu mai e valid link-ul aceasta structura se opreste si afiseaza o eroare. As dori sa sara peste acea eroare si scriptul sa se deruleze in continuare si sa aviseze de exemplu link inexistent. Am incercat cu @ dar cum nu stapanesc prea bine nu am reusit. Multumesc Quote
staticwater Posted May 10, 2011 Report Posted May 10, 2011 (edited) Foloseste metoda try catch.try { //cod "sensibil" }catch(Exception $e) { echo 'Message: ' .$e->getMessage(); }Pt. mai multe informatii google(php try cath)! Edited May 10, 2011 by staticwater Quote