Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 12-08-2009, 12:34 PM   #1
Beta Member
Join Date: Dec 2009
Posts: 4
Default A bit of PHP help?

Ok. I am trying to do a basic scrape and echo results via PHP.
I have the information I am trying to scrape, and I think I am using the correct code, but I am not sure, since it is not showing the array of the results when I try it.

Here is a section of the page source I am trying to scrape

The part I am trying to scrape is the "state":"open"

Here is the code I am using to do this...

$data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%22789151%22%2C0%2C1]]%2C[6511%2C[%22789151%22%2C0]]%2C[6512%2C[%22789151%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260293122');
$regex = '/&quot;state&quot;:&quot;(.+?)&quot;,&quot;player_count&quot;/';
echo $match;
Result is coming back:
1. array(0) { } Array

Completely not showing the results.

I tried scraping another section using the above code, and it did work, but the section that did work did not have any " around it. I am VERY new at PHP, so I am figuring it is something to do with my $regex, and the whole " in the results I am looking for.

EsOne is offline   Reply With Quote
Old 12-09-2009, 05:11 PM   #2
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 8,107
Default Re: A bit of PHP help?

you might find that the quotes are literally just quotes,
so your $regex string might need to be
of course, just to be sure you could use the htmlspecialchars function to encode the text that you are getting into the format that you think that you're getting...

but I'd recommend that you take the page source that you think that you are getting, (i.e with valid HTML, not just quotes).

you then use the http://uk2.php.net/manual/en/functio...ars-decode.php html special chars decode function to remove all the HTML to plain text...

then search for the plain text... (as shown in the code block that I'd changed above for your $regex string

I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-09-2009, 05:36 PM   #3
Site Team
berry120's Avatar
Join Date: Jul 2009
Location: England, UK
Posts: 3,434
Default Re: A bit of PHP help?

I'm tired so might be off, but is your regex right? Agree with what root has said, so looking at the regex alone:
To start with, why the slashes at the beginning and end? And why the (.+?) in the middle?

I'm not sure about escaping characters and suchlike specifically for php, but the regex I'd use would simply be:
Or does that not cover all the possibilities?
berry120 is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are Off

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

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0