This depends on what result you want, really.
If the point is to access a file on the web, like http://www.site.com/foo.dat , you will need to change settings in your webserver. I.e. for apache, you could use this;
AddType application/x-httpd-php .php3 .php .dat
Although this might not be a good idea, given that any file with .dat extension will always be parsed by PHP, i.e. not downloadable from the server.
However, if the point is to save the output of the file to disk, and "force" a specific filename (local), there are basically a couple of techniques. If you use the following;
http://www.site.com/foo.php/foo.dat
foo.php will be executed server-side, but the client will think the file is actually called foo.dat. I've used this a couple of times, and it works very well. (You should probably use header("Content-type: application/octet-stream"); in top of foo.php).
A different solution (wich may be better in some cases), is to tell the browser a filename using header;
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=foo.dat");