vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help needed with parsing (https://vborg.vbsupport.ru/showthread.php?t=31876)

Saint 11-01-2001 05:16 PM

Quote:

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

Mark Hensler 11-02-2001 01:44 AM

Let me try to break it down for you..
PHP Code:

// suck the remote file into a string
$remote_site join(''file("http://remote.domain.com/index.php") );

// now, pattern match for the desired text, in this case,
// $matches[3] will contain the value of the first red block (the name-like thingy)
//$matches[5] will contain the value of the second red block (the image source)
preg_match_all(
    
"|<tr>(.*)<a name=\"(.*)\">(.*):</a>(.*)<IMG SRC=\"(.*)\"(.*)</tr>|Ui",
    
$remote_site$matches);

/**
 * $matches now looks like this:
 * $matches[3][0] = first match for the name block
 * $matches[5][0] = first match for the image block
 * $matches[3][1] = second match for the name block
 * $matches[5][1] = second match for the image block
 * etc.
 */

// loop through all the matches
for ($i=0$i<count($matches[3]); $i++) {
    
// put the name/image info into more user friendly variables
    
$name $matches[3];
    
$image $matches[5];
    
    
// find out what the image source was...
    
if (strstr($image,'grnball.gif')) {
        
// the image source contains "grnball.gif",
    
}
    else {
        
// the imag source does not contain "grnball.gif",
        // so it must be "redball.gif"
    
}
    
    
// do your thingy
    // you might print a new table using the $name/$image from the other site


I hope that helps (probably not =P). If you have a specific question, those are easier to answer.

Saint 11-02-2001 06:18 AM

means I got to repeat that 14 times for the pairs?

and add $matches(0) for all the pairs?

Mark Hensler 11-02-2001 06:37 AM

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:

<?
$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];

    echo "|" . $name . "|" . $image . "|";

    if (strstr($image,'grnball.gif')) {
        echo "the image is a green ball" . "|";
    }
    else {
        echo "the image is a red ball" . "|";
    }
    
    echo "<br>\n";
}
?>


Saint 11-02-2001 06:54 AM

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.

Mark Hensler 11-02-2001 02:57 PM

That URL doesn't work for me.

Saint 11-02-2001 03:12 PM

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.

Mark Hensler 11-02-2001 06:28 PM

try this:
PHP Code:

<?
echo "Yes, I'm running<BR>\n";

$remote_site = join('', file("http://remote.domain.com/index.php") );

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

echo "begining loop<BR>\n";

for ($i=0; $i<count($matches[3]); $i++) {
    $name = $matches[3][$i];
    $image = $matches[5][$i];

    echo "|" . $name . "|" . $image . "|";

    if (strstr($image,'grnball.gif')) {
        echo "the image is a green ball" . "|";
    }
    else {
        echo "the image is a red ball" . "|";
    }
    
    echo "<br>\n";
}
?>


Saint 11-02-2001 06:38 PM

trying now. :D

Saint 11-02-2001 06:43 PM

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.


All times are GMT. The time now is 10:55 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01214 seconds
  • Memory Usage 1,748KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete