 |
 |
How to make Safari render local PHP files as HTML?
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Hi,
I have a bunch of PHP files on my computer. When I drag a php file onto Safari, I want it to render any html in the php file, as sometimes it's all html, and no php. However, it just shows the actual php and html source code in the browser. This is not what I want. I do not want to use a web server either, or rename it to .html.
Any ideas?
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You could add the PHP extension to Safari's Info.plist. On line 151 (in Tiger, at least) is the list of extensions that Safari recognizes as HTML files. You should recognize them. Just add the line "<string>php</string>" there and it should open PHP files as HTML documents.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Aug 2004
Location: FFM
Status:
Offline
|
|
Safari does not execute PHP files. For that you need to serve them from web sharing and turn on PHP (don't know how to do that though).
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I think he knows this. That would be why he said "I want it to render any HTML in the PHP file, as sometimes it's all HTML and no PHP."
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
Install this, turn on web sharing in the Sharing prefpane, and then access your files in Safari from http://localhost/~username/file
I don't know of any way (if there even is one) of doing this without enabling the web server.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Originally Posted by Chuckit
You could add the PHP extension to Safari's Info.plist. On line 151 (in Tiger, at least) is the list of extensions that Safari recognizes as HTML files. You should recognize them. Just add the line "<string>php</string>" there and it should open PHP files as HTML documents.
Where is this file? Thanks!
BTW, you are correct that I know that Safari can't render PHP on it's on. 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
btw, internet explorer does what I want and renders any html in the php file when the php file is dragged into it, but like safari! :-)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
nevermind, i found the file... it's in safari itself! :-)
however, it still just shows html source. :-(
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
maybe the info.plist settings are cached? how would i reload it in? quitting safari and reopening has no effect.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Apr 2002
Location: Illinois
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
King: I have that... along with many other apps that can use the php binary to show the page. But, i'm looking for some way to let safari itself render it, as I clean out files and see what's in each one quickly.
Thanks though
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Info.plist settings are cached by the system. I thought Safari would reload its own settings when the app is launched, but I guess not. I believe touching the app folder will make the system reload the settings. Try going into Terminal and typing touch /Applications/Safari.app . Failing that, a restart ought to do it.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
Originally Posted by timmerk
Hi,
I have a bunch of PHP files on my computer. When I drag a php file onto Safari, I want it to render any html in the php file, as sometimes it's all html, and no php. However, it just shows the actual php and html source code in the browser. This is not what I want. I do not want to use a web server either, or rename it to .html.
You have to use a Webserver. There is no way around this.
PHP is what is known as a server-side language. This means that when you request the file from a server, you don't actually get the file. The server instead runs the file and sends you the results of that run. Browsers neither know nor care what PHP is, because they never see it: they only see the HTML (or CSS, or whatever) the server sends.
Depending on how a PHP file is written, rendering it as HTML may show a lot of things, or very little; sometimes it might not show anything at all. It all depends on how much the author has mixed HTML with their PHP code. Most well-written PHP code actually has very little HTML in it at all.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2004
Location: Vancouver, BC
Status:
Offline
|
|
Milennium, he already knows this! He is not trying to execute PHP locally. What he is trying to do, is render the HTML in a PHP page.
In 10.3, I used to just drag all my php files into the Safari dock icon. That no longer works in Tiger and I must drag the file to the address bar in Safar. This is okay, since I just leave it open and refresh the page when done.
If Safari is not doing this for you, either A, you have a bug, or B, your pages are not correctly formatted. Are you sure you are using the correct doctype, encoding, etc...?
The other day I was browsing and a PHP file from someone's website came up as HTML source. It was really quite strange and I passed it off as a bug, so maybe you are experiencing the same thing.
To others: HE KNOWS HE CANNOT EXECUTE PHP!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
The real question, really, is why would you name a file with all HTML and no PHP code, xxxxxx.php?
It flies in the face of what MIME types and file extensions are all about.
If the file is static HTML, name it xxxxx.html or xxxxx.htm. Otherwise, if it's a JSP, xxxxxx.jps or PHP script, xxxxxxxx.php.
I really don't see the benefit of doing otherwise, and you'll just end up with issues like this.
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Originally Posted by Chuckit
Info.plist settings are cached by the system. I thought Safari would reload its own settings when the app is launched, but I guess not. I believe touching the app folder will make the system reload the settings. Try going into Terminal and typing touch /Applications/Safari.app . Failing that, a restart ought to do it.
Hi Chuck,
I tried the touch thing and restarting, but no luck. I'm pretty sure Safari in 10.3 did what I want. Maybe the info.plist file is still not being loaded? Looking at it, it makes sence that this work work, since it maps php files to the html mime type.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
Originally Posted by Fusion
Milennium, he already knows this! He is not trying to execute PHP locally. What he is trying to do, is render the HTML in a PHP page.
In 10.3, I used to just drag all my php files into the Safari dock icon. That no longer works in Tiger and I must drag the file to the address bar in Safar. This is okay, since I just leave it open and refresh the page when done.
If Safari is not doing this for you, either A, you have a bug, or B, your pages are not correctly formatted. Are you sure you are using the correct doctype, encoding, etc...?
The other day I was browsing and a PHP file from someone's website came up as HTML source. It was really quite strange and I passed it off as a bug, so maybe you are experiencing the same thing.
To others: HE KNOWS HE CANNOT EXECUTE PHP!
Yes, it's doing it for all php files, ones that are formatted correctly, and others that are not. Some have some php in them, others are pure html. Dragging to the address bar doesn't work for me either - it shows the files as html. It worked in 10.3 for me as well.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jul 2004
Status:
Offline
|
|
why enable your apache to run php and turn on web sharing.
then just type yourip / ~username / filename.php
example 12.94.16.19/~Joe/test.php
just put all files in your sites folder under your user name folder
this way you can view them all and it will also execute them because its coming across the internet.
This is what i do for php tests before i upload them to the web.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|