gethostbyaddr(); && return codes?

Newbie alert, newbie alert!!!

ok.  In sh one can get the return status of an executed command using $?.  Is there an equiv in PHP?  Why?  Well, I understand that the return code of gethostbyaddr() is the value of the hostname of the addr (if the function succeeded) and the IP addr if it didn't.  This is all dandy but I want to discern between whether it succeeded or not.

I even confused myself on that...let me give the code I am playing with:

//$r_host = $REMOTE_ADDR;
 $r_host = "xxx.xxx.xxx.xxx";  //a non PTR mapped IP we have.
 $r_hostname = gethostbyaddr($r_host);
 // $counter++;
 // SetCookie ("counter", "$counter", time()+3600);
 if ( ereg("not done yet", $r_hostname) ) { //I haven't quite gotten this regex to work the way I want it to yet.  So I left it out for purposes of this note addition
     printf("Return Status: error.  Could not resolve address -> $r_host<br>\n");
 } else {
    printf("Return Status: good.  Resolved address -> $r_host<br>\n");
 }


Ok.  So see the regex above?  That is the reason I am asking this question.  See...if I could simply get a return status of the just-executed function I could do something similar to:
if ( $return_status == 0 ) { etc etc }.

Any thoughts?
Thanks in advance
Jim
LVL 1
notjamesAsked:
Who is Participating?
 
maxkirConnect With a Mentor Commented:
$r_host = "xxx.xxx.xxx.xxx";  //a non PTR mapped IP we have.

$r_hostname = gethostbyaddr($r_host);
if (  $r_hostname == $r_host ) {
  printf("Return Status: error.  Could not resolve address->$r_host<br>\n");
} else {
  printf("Return Status: good.  Resolved address->$r_hostname<br>\n");
}

echo was used in PHP/FI.
print call was added in PHP3, but echo is still supported.
0
 
gravityCommented:
Have you tried using :
if (!$r_hostname)

Also, it's a thing of personal choice, I but prefer to use echo to print or printf... just a little note :)
0
 
notjamesAuthor Commented:
Well.  I didn't get an error but it also didn't work.  Any particular reason why you prefer echo over printf()?
0
 
notjamesAuthor Commented:
I should have thought of this but I was thinking too difficult.  I think there should be a way to check the return code on a function imho.  Im a newbie at PHP and Im trying to learn C as well so the printf() seems to be what I prefer.  It doesn't *seem* like there is an advantage of the echo command over printf().  If there is I'd love to know it.

Thanks again!  Points rewarded...
0
 
abuckCommented:
i like to use echo because it doesn't require me to use parentheses. its just a little quicker.
0
All Courses

From novice to tech pro — start learning today.