What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Question...

Question...
Author: Message:
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. Question...
Hello guys, another web based question :)

With the code that collects a number from a certain website, is constantly failing when the connection that site isnt working...here is the code.
code:
$data = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die("Could not get data");
$usercount = preg_replace("/<usercount>([0-9]+)<\\/usercount>/", "\\1", $data);
echo $data;
Is there a way i can make it so that when the website it collects data from isnt working it just displays "Some" or something, because the "die blablabla" doesnt seem to do that *-)
...there used to be a signature here :)
07-02-2007 12:25 PM
Profile PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
RE: Question...
first, you have to remove the die message. then, put if statements around any place that uses the contents of $data to see if it is null or empty
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
07-02-2007 03:20 PM
Profile PM Web Find Quote Report
user13774
Disabled Account


Posts: 1119
Joined: Apr 2003
Status: Away
RE: Question...
What MeEtc means:

code:
$data = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action");
if ($data)
{
$usercount = preg_replace("/<usercount>([0-9]+)<\\/usercount>/", "\\1", $data);
// and all the other stuff you want to do with $data
echo $data;
}
else
{
echo("Unable to retreive data");
}

07-02-2007 08:26 PM
Profile PM Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
RE: Question...
code:
$data = @file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die("Could not get data");
$usercount = preg_replace("/<usercount>([0-9]+)<\\/usercount>/", "\\1", $data);
echo $data;
Shows the number of users.

code:
$data = @file_get_contents("http://www.habbo.com.au/habbo_count_xml.actionaa") or die("Could not get data");
$usercount = preg_replace("/<usercount>([0-9]+)<\\/usercount>/", "\\1", $data);
echo $data;
(Notice the aa at the end of the URL, bumming it up). This works as it should for me. (ie, Could not get data is sent to the browser).

Notice the @ in front of file_get_contents - this disables warnings. (Edit: For that function).

You could also do (as the last line):
echo ($data) ? $data : "No Data";

This post was edited on 07-03-2007 at 10:02 AM by andrewdodd13.
[Image: AndrewsStyle.png]
07-03-2007 10:01 AM
Profile E-Mail PM Web Find Quote Report
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. RE: Question...
quote:
Originally posted by Markus
What MeEtc means:

code:
$data = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action");
if ($data)
{
$usercount = preg_replace("/<usercount>([0-9]+)<\\/usercount>/", "\\1", $data);
// and all the other stuff you want to do with $data
echo $data;
}
else
{
echo("Unable to retreive data");
}


Thanks Markus, will use that in the future :)
Thanks all :]
...there used to be a signature here :)
07-04-2007 07:22 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On