holatole Posted October 10, 2007 Share Posted October 10, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/72653-does-file_get_contents-convert-dates-on-its-own/ Share on other sites More sharing options...
roopurt18 Posted October 10, 2007 Share Posted October 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72653-does-file_get_contents-convert-dates-on-its-own/#findComment-366336 Share on other sites More sharing options...
holatole Posted October 10, 2007 Author Share Posted October 10, 2007 hahahah well that's a relief! I thought I was really going bonkers with this one. Is there a way for me to fake the agent so that donbest thinks it's a browser? If not, could you recommend a possible solution for this? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/72653-does-file_get_contents-convert-dates-on-its-own/#findComment-366338 Share on other sites More sharing options...
roopurt18 Posted October 10, 2007 Share Posted October 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72653-does-file_get_contents-convert-dates-on-its-own/#findComment-366349 Share on other sites More sharing options...
Orio Posted October 10, 2007 Share Posted October 10, 2007 If you want to mess with the user-agent, use the cURL library. You can decide whatever user-agent you want to be using cURL. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72653-does-file_get_contents-convert-dates-on-its-own/#findComment-366351 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.