Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 30 Oct 2001, 23:15
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Help needed with parsing

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?
Reply With Quote
  #2  
Old 31 Oct 2001, 02:01
MrLister's Avatar
MrLister MrLister is offline
 
Join Date: Oct 2001
post the code here.... you'll get much more response... if the code is too big then post the problem area.
Reply With Quote
  #3  
Old 31 Oct 2001, 06:13
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
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()
Reply With Quote
  #4  
Old 31 Oct 2001, 13:26
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Originally posted by MrLister
post the code here.... you'll get much more response... if the code is too big then post the problem area.
The HTML code or the php code?

I know nothing about PHP, am still learning.

If it's the HTML code, yes I can paste it here.
Reply With Quote
  #5  
Old 31 Oct 2001, 14:16
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
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&nbsp;&nbsp;<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.
Reply With Quote
  #6  
Old 31 Oct 2001, 14:38
MrLister's Avatar
MrLister MrLister is offline
 
Join Date: Oct 2001
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.
Reply With Quote
  #7  
Old 31 Oct 2001, 14:55
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Ok thanks
Reply With Quote
  #8  
Old 31 Oct 2001, 16:03
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
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.
Reply With Quote
  #9  
Old 31 Oct 2001, 20:39
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
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.
Reply With Quote
  #10  
Old 31 Oct 2001, 21:12
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
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)

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

functions docs: file(), join(), preg_match_all(), strstr()

Good Luck,
Reply With Quote
  #11  
Old 01 Nov 2001, 18:16
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Originally posted by Mark Hensler
[B]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)

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
Reply With Quote
  #12  
Old 02 Nov 2001, 02:44
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Let me try to break it down for you..

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I hope that helps (probably not =P). If you have a specific question, those are easier to answer.
Reply With Quote
  #13  
Old 02 Nov 2001, 07:18
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
means I got to repeat that 14 times for the pairs?

and add $matches(0) for all the pairs?
Reply With Quote
  #14  
Old 02 Nov 2001, 07:37
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
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....

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #15  
Old 02 Nov 2001, 07:54
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 20:31.

Layout Options | Width: Wide Color: