![]() |
am new to php and needed help in parsing some html code from an external webpage (with consent from owner)
and outputing it on the index.php of vB. Not parsing the whole webpage though just some of it. Any anyone help? |
post the code here.... you'll get much more response... if the code is too big then post the problem area.
|
This will involve pattern matching. You'll need to know what's before and after the text you want.
If you want to read docs on some of the functions you might use... eregi(), file(), preg_match() |
Quote:
I know nothing about PHP, am still learning. :( If it's the HTML code, yes I can paste it here. |
This is the HTML from the site I want to parse
<TABLE WIDTH="70%" > <TR> <TD><FONT SIZE=+1><a name="patch">Patch Server:</a></FONT></TD> <TD><IMG SRC="http://ultima.lightning.net/uo/img/grnball.gif" HEIGHT=17 WIDTH=17 ALIGN=TOP> UP! for 57h 20m 06s</TD> </TR> <TR> <TD><FONT SIZE=+1><a name="login">Login Server:</a></FONT></TD> <TD><IMG SRC="http://ultima.lightning.net/uo/img/grnball.gif" HEIGHT=17 WIDTH=17 ALIGN=TOP> UP! for 97h 49m 06s</TD> </TR> <TD><FONT SIZE=+1><a name="AOLLegends">AOL Legends:</a></FONT></TD> <TD><IMG SRC="http://ultima.lightning.net/uo/img/grnball.gif" HEIGHT=17 WIDTH=17 ALIGN=TOP> UP! for 1h 31m 06s <A HREF="http://ultima.lightning.net/uo/en/history/AOLLegends.html"><FONT SIZE="-2">[details]</FONT></a></TD> </TR> Note that I only need to parse some of it not the whole HTML so some stripping need to be done. i.e I only need to parse the code I highlighted in red above. The page that I'm parsing the HTML from refreshed every 60 secs. |
As Mark already mentioned try looking into eregi(), file(), preg_match() on php.net and i'm pretty sure there are a few scripts that do something like this... you could try and look them up at hotscripts.com and look at the source and get an idea from there.
|
Ok thanks
|
What you'll be doing is pattern matching. So, you have to know what is surrounding the text you want.
Do you only want the those two pairs in red? Or, do you want anything in this pattern: <TR> <TD><FONT SIZE=+1><a name="login">TEXT TEXT TEXT</a></FONT></TD> <TD>TEXT TEXT TEXT HEIGHT=17 WIDTH=17 ALIGN=TOP> UP! for 97h 49m 06s</TD> </TR> When your pattern matching, you want to be very specific. |
I just want the 2 pair in red.
In total there's about 14 pairs of that on that page. But output differently on my page, I'll want to replace his image file with my own image file. But i need to know which image file is on his page at that time cos there's 2 type, a grnball.gif and a redball.gif I'll name mine the same too, but will be of different pic. Thanks for replying Mark. |
Wait.. do you want only those 2 pairs (login server, aol legends), or all 14 pairs? (I'm looking at pairs as the text and image)
Some "Quickie Code" (untested) PHP Code:
Good Luck, |
Quote:
Sorry all the 14 pairs. Yes, pairs as in the text and image. I'm still trying to absorb your code. Am a newbie at this. :( Thanks |
Let me try to break it down for you..
PHP Code:
|
means I got to repeat that 14 times for the pairs?
and add $matches(0) for all the pairs? |
No, it is already looping through all the pairs. See where I said "// do your thingy"?
Try it.. just make a new file, and through this in there.... PHP Code:
|
Warning: file("http://ulitma.lightning.net/uo/index.html") - Undefined error: 0 in /usr/local/www/vhosts/nettiq.com/htdocs/serverstats.php on line 2
Warning: Bad arguments to join() in /usr/local/www/vhosts/nettiq.com/htdocs/serverstats.php on line 2 I got this error when I try to run the php script. |
That URL doesn't work for me.
|
my mistake
typo http://ultima.lightning.net/uo/index.html I corrected it and when i run the php it gives me a blank screen. |
try this:
PHP Code:
|
trying now. :D
|
Nope.
Only get this 2 line Yes, I'm running begining loop I should replace just the $remote_site = join('', file("http://remote.domain.com/index.php") ); to http://ultima.lightning.net/uo/index.html right? all the code stays. |
$remote_site = join('', file("http://remote.domain.com/index.php") );
should become $remote_site = join('', file("http://ultima.lightning.net/uo/index.html") ); |
Yup.
That's how I did it. Only got those 2 lines |
I have some time right now.. let me try playing with it.
|
OK.. this works for me. You can edit it to say whatever you need..
PHP Code:
|
That works!
Thanks alot for your time Mark! |
With table, and images...
PHP Code:
|
new patterm:
Code:
<tr bgcolor="#ffc858"> PHP Code:
|
All times are GMT. The time now is 07:38 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|