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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
maxkirCommented:
$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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.