[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-04
4
Medium Priority
?
245 Views
Last Modified: 2012-05-11
Dear Experts

This script wont work for some reason...

$ipaddress = gethostbyname($domain);

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

echo $status;


I know the $ipaddress is 127.0.0.1 but nothing echos

Thanks in advance
0
Comment
Question by:maccaj51
  • 2
4 Comments
 
LVL 39

Expert Comment

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

echo $status;
0
 
LVL 2

Expert Comment

by:Gnarf
ID: 35687629
Are you quite sure the ip address returned in fact is 127.0.0.1? 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

HTH
Gnarf
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 35687634
if ($ipaddress == "127.0.0.1") { $status = "offline";}
else { $status = "online"; }

echo $status;

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

Author Closing Comment

by:maccaj51
ID: 35687639
pratima_mcs GREAT SPOT!!!

Many Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 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