file_get_contents trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chuckbalzer
Forum Newbie
Posts: 1
Joined: Fri Sep 02, 2011 8:20 pm

file_get_contents trouble

Post by chuckbalzer »

Hi,

I'm loading google search results with

Code: Select all

$cocntents = file_get_contents("http://www.google.com/products/catalog?q=036725235182&hl=en&cid=6520112632679181641&os=sellers#scoring=tp");
I want the results to be sorted by total price, hence #scoring=tp

What is weird is that if I take the link and copy it into a new browser window it displays the results exactly as I would like to see them.

but if I echo $cocntents the page does not sort by total price. It sorts by the default Relevance. So my script see the page sorted incorrectly.

Does anyone know how I can get around this? Maybe a different load method or different approach all together? Thanks in advance for the help.

Chuck
2-d
Forum Newbie
Posts: 6
Joined: Fri Sep 02, 2011 9:50 pm

Re: file_get_contents trouble

Post by 2-d »

Hey there,

I think the issue has to do with how the site works. The part after hash (#) is part of their javascript. Whats actually happening on that site, is the normal order is displaying on load, then they have some javascript to parse out the variables after the # and then load the order.

I don't believe file_get_contents will parse any javascript, you are just getting the flat file. So it will always be in the default order. If you turn off javascript on your browser and then go to that site, you should see the same order you are getting through your script.

You may need to just parse it out and then sort in your script.

Best of luck.
Post Reply