...

View Full Version : If error then continue and not die - possible?



oskare100
03-07-2008, 11:13 PM
Hello,
I have the following code:

$request = file_get_contents($request_url) or die("feed not loading");

If the file_get_contents($request_url) doesn't load/respond then the script echoes "feed not loading" and stops.

I want the script to echo "feed not loading" and then continue and just skip that part of the script that needed the file contents.

Is that possible?

Best Regards
Oskar R

Fumigator
03-07-2008, 11:37 PM
The "or die()" syntax is really just shorthand for a condition check for a "false" return, ie. if (!condition) {}. So you can easily do



$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading";
} else {
//continue with your coding goodness here
}

oesxyl
03-08-2008, 12:19 AM
The "or die()" syntax is really just shorthand for a condition check for a "false" return, ie. if (!condition) {}. So you can easily do



$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading";
} else {
//continue with your coding goodness here
}
// now is safe to have code here


agree with condition to stop the execution of anything outside of if/else



$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading";
exit; // this really die
} else {
//continue with your coding goodness here
}
// now is safe to have code here


best regards

rafiki
03-08-2008, 12:30 PM
agree with condition to stop the execution of anything outside of if/else



$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading";
exit; // this really die
} else {
//continue with your coding goodness here
}
// now is safe to have code here


best regards
doesn't want to die....

$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading"; //notify there is an error.
}

// now is safe to have code here

oesxyl
03-08-2008, 04:03 PM
doesn't want to die....

$request = file_get_contents($request_url);
if (!$request) {
echo "feed not loading"; //notify there is an error.
}

// now is safe to have code here

this is wrong! If $request is false, it display the message and continue with what you think that is safe.
That is the reason of exit there. I don't correct Fumigator code, I just add the posibility to add code not related with $request to the page.




I want the script to echo "feed not loading" and then continue and just skip that part of the script that needed the file contents.

I'm sorry, is my fault, rafiki solution work


best regards

CFMaBiSmAd
03-08-2008, 04:17 PM
Read the OP's post, carefully.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum