473,387 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Obtaining info from a site using PHP

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
Jul 31 '08 #1
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.
Jul 31 '08 #2
Ok, I see. If i get this right, my code should start as:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. define('_GAMETYPE', 'Servername:');
  4. define('_PLAYERS', 'Players:');
  5. define('_GAMETYPE', 'Gametype:');
  6. define('_OFFLINE', 'Offline');
  7. define('_ONLINE', 'Online');
  8.  
  9. //********
  10.  
  11. if $file_get_contents( "http://nw4.novaworld.net/bhd_3_list.lob?page=0
  12. " [, FILE_TEXT [, NULL [, OFFSET [, 7 ]]]] ) = "{a.s.u}"
  13.  
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.
Jul 31 '08 #3
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
Aug 1 '08 #4
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get the HTML of the page
  3. $html = file_get_contents("http://www.google.com");
  4.  
  5. // Create a regular expressio that looks for the 
  6. //  <title> tags.
  7. $regEx = '/\<title\>(.*)\<\/title\>/is';
  8.  
  9. // Search, using the regular expression
  10. if(preg_match($regEx, $html, $matches)) {
  11.     // Show the title
  12.     echo "The title is: ". $matches[1];
  13. }
  14. else {
  15.     // It failed!
  16.     echo "Didn't work!";
  17. }
  18. ?>
  19.  
You would have to do something similar, replacing the search with something that would look for the info you need.
Aug 1 '08 #5
Thanks alot! This is my code so far:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. $html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0")
  5.  
  6. $regEx = '\{a\.s\.u\}'
  7.  
  8. if(preg_match($regEx, $html, $matches))
  9. {
  10.     echo "<img src="http://asu-clan.info/html/serverstatus/online.bmp">Server Online!"
  11. }
  12. else
  13. {
  14.     echo "<img src="http://asu-clan.info/html/serverstatus/offline.bmp">Server Offline"
  15. }
  16. ?>
  17.  
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 ?
Aug 2 '08 #6
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
  4.  
  5. $regEx = 'a\.s\.u SAS';
  6.  
  7. if (preg_match($regEx, $html, $matches)); {
  8.     echo "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
  9. }
  10. else {
  11.     echo "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
  12. }
  13. ?>
  14.  
Aug 3 '08 #7
I cannot seem to edit my latest post, Im sorry to reply again :(

I now have this code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
  4.  
  5. $regEx = 'a\.s\.u SAS';
  6. if (preg_match_all($regEx, $html, $matches)) {
  7.     print_r($matches);
  8.     print "a.s.u SAS Server";
  9.     print "<br>";
  10.     print "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
  11. } else {
  12.     print "a.s.u SAS Server";
  13.     print "<br>";
  14.     print "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
  15. }
  16.  
  17. ?>
  18.  
  19.  
  20.  
  21. <?php
  22.  
  23. $html = file_get_contents("http://nw4.novaworld.net/bhd_3_list.lob?page=0");
  24.  
  25. $regEx = '\{a\.s\.u\}';
  26. if (preg_match_all($regEx, $html, $matches)) {
  27.     print "a.s.u Sniper Server";
  28.     print "<br>";
  29.     print "<img src=http://asu-clan.info/html/serverstatus/online.bmp>Server Online!";
  30. } else {
  31.     print "a.s.u Sniper Server";
  32.     print "<br>";
  33.     print "<img src=http://asu-clan.info/html/serverstatus/offline.bmp>Server Offline";
  34. }
  35.  
  36. ?>
  37.  
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
Aug 3 '08 #8
Resolved, thanks for help though Atli.
Aug 6 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
7
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...
3
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...
1
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....
1
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...
11
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...
3
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...
4
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...
2
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.