Jump to content

Does file_get_contents convert dates on its own?


holatole

Recommended Posts

Hi, this is something I've been trying to get to work for some time and don't understand why it happens:

 

I'm trying to use file_get_contents to display this page: http://www.donbest.com/schedule/getRotation.html?bookType=1&eventDate=20071029

 

The problem is when it gets to this line:

P: 5:30PM  C: 7:30PM  E: 8:30PM

 

Once I use echo to display the content on a page, it converts those times to full dates like this:

P: Mon Oct 29 17:30:00 PDT 2007 C: Mon Oct 29 19:30:00 PDT 2007 E: Mon Oct 29 20:30:00 PDT 2007

 

This would be a simplified version of my code.

$html = file_get_contents("http://www.donbest.com/schedule/getRotation.html?bookType=1&eventDate=20071029");
echo $html;

 

I'm actually formatting the content with regex and saving it to seperate files and stuff, but my problem starts right on that initial line.

 

Does anybody know why this happens and how can I fix this?

Thanks!

Link to comment
Share on other sites

Well, I don't see why file_get_contents() would go to the trouble of converting dates itself.

 

1)  It's just extra overhead

 

2)  It's undesirable; if I'm calling a function to get a file's contents I want the contents, not modified contents.

 

My guess is the difference in format is occurring at donbest.com

 

I bet their applet is set up to spit the date out in a human-friendly format if the requesting agent is a browser and spits it out in a computer friendly format for robots or other requests, such as that made by file_get_contents.

 

(edit) BTW you're not crazy, I was able to reproduce the same exact thing.

 

(edit2) You can test this with a plug-in that allows you to switch user agents.  Just have your browser identify itself as a google or yahoo bot and try to access the same page.

Link to comment
Share on other sites

file_get_contents():

http://www.php.net/file_get_contents

 

There is a reference there to setting up a stream context, which leads here:

http://www.php.net/manual/en/function.stream-context-create.php

 

It looks like you can use the stream context to customize your request method and headers.  Try setting a header that identifies your user agent as IE or FF.

 

A list of user agents:

http://www.user-agents.org/index.shtml

 

That's as much as I can help you with.  You'd have to wait until someone else more familiar with HTTP headers comes along or Google 'HTTP headers' to get more.

 

If you have whatever is required installed, you might be able to just create a test script and use http_get_request_headers() to echo the ones sent by your browser.  Then you can just duplicate them in your context stream.

http_get_request_headers():

http://www.php.net/manual/en/function.http-get-request-headers.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.