Hi,
I would write the function as below
Code: Select all
<?php
//Output Feedblitz Counter
function openStats($link,$mode=NULL){
$m = (is_null($mode)) ? $mode : 'r';
$f=file_get_contents($link,$m);
$stats = (strlen($f)==0) ? 'There was an error...' : $f;
return $stats;
}
?>
<?=openStats("http://assets.feedblitz.com/chicklets/email/i/2d/XXXXX.txt"); ?>
why is_null ?
improves readability. Behavior of empty function is not as apparent as behavior of is_null function. for example empty("0") return true.
why strlen?
Strictly speaking, if that file contains the string "0" your code will echo the 'There was an error...' message, because "0" is considered to be empty.
Strlen returns 0 for both the empty string and the boolean value false, the two possible return values of `file_get_contents` you would like to echo an error message.
hope this doesnt sound stupid.....
Regards,
Sandeep/Max