Possible to read JavaScript results into a string?
| From: | Brian Dunning | Date: | Mon, 08 Aug 2005 17:38:54 +0000 |
| Subject: | Possible to read JavaScript results into a string? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-220235@lists.php.net to get a copy of this message | ||
I have an external JavaScript that I use on several of my sites. It returns a web counter and does some other logging. It's accessed like this:
<script language="javascript" src="http://www.mydomain.com/log.js"></script>
No rocket science there, this is common and it works great. That call returns a block like this:
document.write('<a bunch of html>')
What I want to know is: is it possible to retrieve the above outputted code into a string, rather than outputting it directly to the browser? Nothing I've tried works, and I also tried this using a Google AdSense call to make sure there was not a problem in my JavaScript. Here's what I tried and what happened:
<?php
$x = file_get_contents('http://www.mydomain.com/log.js');
// also tried urlencode() but that did not help
?>
The result:
Warning: main(http://www.mydomain.com/log.js) [function.main]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in c:\Inetpub\wwwroot\test.php on line 2