Ex1t Posted August 4, 2015 Share Posted August 4, 2015 I have this code $url = 'www.site.com'; $list = array("ext.pdf", "ext_1.pdf", "ext_2.pdf", "ext_3.pdf", "ext_4.pdf"); foreach($list as $lists) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_URL, $url.$lists); $result = curl_exec($ch); curl_close($ch); if (preg_match("/200 OK/", $result)){ echo "<p>$url$lists</p>"; } else if (preg_match("/401 Unauthorized/", $result)) { echo "<p>$url$lists</p>"; } } Now, if this script finds nothing i want to echo 'Not found'..I can do it with 'else' but it displays 5 times..I tried with exit() but there is also problem.. Help please Quote Link to comment https://forums.phpfreaks.com/topic/297623-curl-problem/ Share on other sites More sharing options...
requinix Posted August 4, 2015 Share Posted August 4, 2015 Use a variable to track if any files were found. It starts with the value false and you set it to true when you find the file. After the loop you check the variable. Quote Link to comment https://forums.phpfreaks.com/topic/297623-curl-problem/#findComment-1518004 Share on other sites More sharing options...
Ex1t Posted August 4, 2015 Author Share Posted August 4, 2015 Can you give me code for example? Quote Link to comment https://forums.phpfreaks.com/topic/297623-curl-problem/#findComment-1518036 Share on other sites More sharing options...
requinix Posted August 4, 2015 Share Posted August 4, 2015 Umm, well, $found = false;and then // if found the file { $found = true; // }and then later if (!$found) { echo "Not found"; } Quote Link to comment https://forums.phpfreaks.com/topic/297623-curl-problem/#findComment-1518039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.