Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2001, 10:15 PM
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 01:01 AM
MrLister's Avatar
MrLister MrLister is offline
 
Join Date: Oct 2001
Posts: 434
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 05:13 AM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 12:26 PM
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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 10-31-2001, 01:16 PM
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 01:38 PM
MrLister's Avatar
MrLister MrLister is offline
 
Join Date: Oct 2001
Posts: 434
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 01:55 PM
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok thanks
Reply With Quote
  #8  
Old 10-31-2001, 03:03 PM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 07:39 PM
Saint's Avatar
Saint Saint is offline
 
Join Date: Oct 2001
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 10-31-2001, 08:12 PM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
// suck the remote file into a string
$remote_site join(''file("http://remote.domain.com/index.php") );

preg_match_all(
    
"|<tr>(.*)<a name=\"(.*)\">(.*):</a>(.*)<IMG SRC=\"(.*)\"(.*)</tr>|Ui",
    
$remote_site,$matches);

for (
$i=0$i<count($matches[3]); $i++) {
    
$name $matches[3];
    
$image $matches[5];
    if (
strstr($image,'grnball.gif')) {
        
// green ball
    
}
    else {
        
// red ball
    
}
    
    
// do your thingy
    

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

Good Luck,
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 04:04 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04106 seconds
  • Memory Usage 2,256KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete