I've searched using several terms, but couldn't find my answer. If this question has been asked before, I appologise.
I'm trying to use PHP to get some info from a website, the website sometimes contains 1 or 2 more pages:
http://nw4.novaworld.net/bhd_3_list.lob?page=0
What I want is, as soon as there is a 'Game Name' containing {a.s.u}, make a PHP script get the 'Game Type' and 'Total Players' next to it, and format the info like this:
Game Name
Game Type
Total Players
Online (Or display Offline if there is no Game Name containing {a.s.u})
I actually don't have a clue where to start with, as my experience with PHP is very low. I was thinking using a Get command, but I don't know if such a command is possible with PHP ?
Any help, tips or info about how I could get this done is very appreciated.
Thanks in advance,
Evolution445
8 1638 Atli 5,058
Expert 4TB
You could get the HTML markup of that page by using the file_get_contents function.
Then it would just be a matter of parsing the HTML into something useful.
I would recommend looking into regular expressions for that, using the PCRE functions.
Ok, I see. If i get this right, my code should start as: -
<?php
-
-
define('_GAMETYPE', 'Servername:');
-
define('_PLAYERS', 'Players:');
-
define('_GAMETYPE', 'Gametype:');
-
define('_OFFLINE', 'Offline');
-
define('_ONLINE', 'Online');
-
-
//********
-
-
if $file_get_contents( "http://nw4.novaworld.net/bhd_3_list.lob?page=0
-
" [, FILE_TEXT [, NULL [, OFFSET [, 7 ]]]] ) = "{a.s.u}"
-
maxlen Should thus be 7 because what I'm searching for contains just 7 characters, or should maxlen be NULL cause it has to search a whole page for that ' {a.s.u} ' text ?
And how would I get the Offset where it should read from ?
Sorry if this sounds quite 'nooby' or stupid, but I'm really not experienced with PHP.
Sorry to add this, but on my website I made a small block using HTML of how I want the result to look like:
http://img45.imageshack.us/img45/8514/serverstatus1ez9.png
Now it would only have to be PHP code to update the name, TDM, 0/16 and offline/online. How would I be able to get the exact position of where it has to start obtaining info? As on the page Im attemping to get info from, there's a lot more games using the same gametype (TDM) and maximum players ( 0/16 ):
http://nw4.novaworld.net/bhd_3_list.lob?page=0
Atli 5,058
Expert 4TB
You would have to get the entire HTML of the resource site and have PHP look through the HTML for the information you need.
Like, if I needed the title of Google's main page, I could do: -
<?php
-
// Get the HTML of the page
-
$html = file_get_contents("http://www.google.com");
-
-
// Create a regular expressio that looks for the
-
// <title> tags.
-
$regEx = '/\<title\>(.*)\<\/title\>/is';
-
-
// Search, using the regular expression
-
if(preg_match($regEx, $html, $matches)) {
-
// Show the title
-
echo "The title is: ". $matches[1];
-
}
-
else {
-
// It failed!
-
echo "Didn't work!";
-
}
-
?>
-
You would have to do something similar, replacing the search with something that would look for the info you need.
Thanks alot! This is my code so far: -
<?php
-
-
-
$html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0")
-
-
$regEx = '\{a\.s\.u\}'
-
-
if(preg_match($regEx, $html, $matches))
-
{
-
echo "<img src="http://asu-clan.info/html/serverstatus/online.bmp">Server Online!"
-
}
-
else
-
{
-
echo "<img src="http://asu-clan.info/html/serverstatus/offline.bmp">Server Offline"
-
}
-
?>
-
Sorry to bother with another question, but as I said, the page I'm trying to get info from sometimes consists of multiple pages (1 or 2 more), then it looks like this:
http://nw4.novaworld.net/bhd_3_list.lob?page=0
http://nw4.novaworld.net/bhd_3_list.lob?page=1
http://nw4.novaworld.net/bhd_3_list.lob?page=2
Is it possible to use a star ( * ) at the pagenumber ? ( page=* ) Will this make it start from page 0 to page 99999999 till it found ' {a.s.u} ', or is there a better way ?
I also seem to be getting an error with the above code:
Parse error: syntax error, unexpected T_VARIABLE in /home/rsksquad/public_html/html/blocks/block-serverstatus.php on line 6
I've tried some things such as changing the regEx into one single letter but it just doesnt seem to work
EDIT:
I fixed this error now, but now it says:
unexpected T_ELSE in /home/rsksquad/public_html/html/blocks/block-serverstatus.php on line 10 -
<?php
-
-
$html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
-
-
$regEx = 'a\.s\.u SAS';
-
-
if (preg_match($regEx, $html, $matches)); {
-
echo "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
-
}
-
else {
-
echo "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
-
}
-
?>
-
I cannot seem to edit my latest post, Im sorry to reply again :(
I now have this code: -
<?php
-
-
$html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
-
-
$regEx = 'a\.s\.u SAS';
-
if (preg_match_all($regEx, $html, $matches)) {
-
print_r($matches);
-
print "a.s.u SAS Server";
-
print "<br>";
-
print "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
-
} else {
-
print "a.s.u SAS Server";
-
print "<br>";
-
print "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
-
}
-
-
?>
-
-
-
-
<?php
-
-
$html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
-
-
$regEx = '\{a\.s\.u\}';
-
if (preg_match_all($regEx, $html, $matches)) {
-
print "a.s.u Sniper Server";
-
print "<br>";
-
print "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
-
} else {
-
print "a.s.u Sniper Server";
-
print "<br>";
-
print "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
-
}
-
-
?>
-
I still dont know how I can make it read more sites than just one, I tried several things but they only resulted in errors.
With my current code, I seem to get these errors:
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in /home/rsksquad/public_html/html/blocks/block-serverstatus.php on line 6
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in /home/rsksquad/public_html/html/blocks/block-serverstatus.php on line 23
Resolved, thanks for help though Atli.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Martin |
last post by:
Dear Group
Sorry for posting this here. I'm desperate for a solution to this
problem and thought some of you might have come across it with .NET
and SQL Server.
Let's assume I've the following...
|
by: Privacy Advocate |
last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an
effort to get factual answers from JavaScript experts//
Simply put; Is it possible to obtain the real (actual) IP address of...
|
by: Wade |
last post by:
08242005 1416 GMT-5
Recently some of you helped me with a script to change images. Well I
was asked to make a change to the script and not knowing if what the
school system is even possible, Ill...
|
by: Jason \(MFT1\) |
last post by:
I'm using cookieless sessions and forms authentication for a website which
only has light activity.
I am using the authentication to protect only certain folders and all that
works just fine....
|
by: Terry Mulvany |
last post by:
Grettings,
Normally I can use Request.RawUrl to get the 'current' page (amongst many
other things). But in the case of using a Server.Transfer
but the path from the root of
the site . So if...
|
by: John Nagle |
last post by:
The Python SSL object offers two methods from obtaining
the info from an SSL certificate, "server()" and "issuer()".
The actual values in the certificate are a series of name/value
pairs in ASN.1...
|
by: psujkov |
last post by:
Hi everybody,
int f(int a, int b) { return a + b; };
is it possible to obtain this function signature - int (int, int) in
this case - for use in boost::function_traits ?
e.g. std::cout << "f's...
|
by: =?Utf-8?B?anBzaG9ydHN0dWZm?= |
last post by:
Hi, not sure if this is the right place for this but it was definitely the
closest I could find.
I am having trouble with the GetFileVersionInformation/VerQueryValue
functions and was wondering...
|
by: anumsajeel |
last post by:
Hi,
Error Message:-
error connecting: Timeout expired. The timeout period elapsed prior to
obtaining a connection from the pool. This may have occurred because all pooled
connections were...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |