How do i check if a string contains a specific number?

Posted on 2011-05-04
Last Modified: 2012-05-11
Dear Experts

This script wont work for some reason...

$ipaddress = gethostbyname($domain);

if ($ipaddress == "") { $status == "offline";}
else { $status == "online"; }

echo $status;

I know the $ipaddress is but nothing echos

Thanks in advance
Question by:maccaj51
    LVL 39

    Expert Comment

    by:Pratima Pharande
    if ($ipaddress == "") { $status = "offline";}
    else { $status = "online"; }

    echo $status;
    LVL 2

    Expert Comment

    Are you quite sure the ip address returned in fact is Either, gethostbyname will return null (misspelling of the host name) or the IP adress retuirned is the one assigned to your computer. In case of a company network this may one starting with  192.168.

    To find out:
    Check if $ipaddress is null
    If it is not, use the echo command or something similar to print it out
    Enclose the output into special characters, lets say the pipe sign. This will help you detect leading or trailing white spaces

    LVL 39

    Accepted Solution

    if ($ipaddress == "") { $status = "offline";}
    else { $status = "online"; }

    echo $status;

    you are using "==" for assignmetn change it as above
     $status = "offline";

    Author Closing Comment

    pratima_mcs GREAT SPOT!!!

    Many Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now