Shipton Posted March 6, 2008 Share Posted March 6, 2008 I have no idea what the hell is going on, got me baffled up the wazoo. I'm just learning php, and I'm doing your run-of-the-mill Hello World! thing-a-ma-jigger. Code below. However, when I run it, nothing shows up at all. Blank page. Funny part is, I have another file called phptest.php, which makes it spew out all the relevant information about php to verify it's working, which it apparently is, because that one line of code works. I have a virtual host set up on my computer via Apache, with PHP and MySQL installed. The file below is called index.html. I am accessing it via localhost, not via C:\whatever, so that's not the issue. Any help is greatly appreciated. <html> <head> <title>Main Index</title> </head> <body> <?php echo "Hello world!" ?> </body> </html> I changed it to .php, and thus it works. I'm a class-A idiot. But does it have to be .php, or can an HTML document ever contain PHP, much as it can contain javascript? Quote Link to comment Share on other sites More sharing options...
dmccabe Posted March 6, 2008 Share Posted March 6, 2008 if should work as a php or html file, but you are missing a ; at the end of the echo "Hello world!" line eg: echo "hello world!"; Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted March 6, 2008 Share Posted March 6, 2008 Yes, it can work with a .html extension (or, indeed, any other extension you like). It's an apache setting. Ill just try and find it for you. Edit: Find this line in your http.conf: AddType application/x-httpd-php .php Then add this line: AddType application/x-httpd-php .html On a side note, php wont throw an error for a missing semi-colon if the php is closed directly after. Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted March 6, 2008 Share Posted March 6, 2008 To run html files as php, Add this to the .htaccess file in the directory that you want your html files to act like php files: AddType application/x-httpd-php .html Quote Link to comment Share on other sites More sharing options...
dmccabe Posted March 6, 2008 Share Posted March 6, 2008 On a side note, php wont throw an error for a missing semi-colon if the php is closed directly after. Well you learn something new every day Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2008 Share Posted March 6, 2008 Getting into the habit of leaving off the last semi-colon before a closing ?> tag will cause you problems when you add lines of code after that line and forget that you need to go back and add the missing semi-colon. It is best to not take lazy-way short cuts when writing code. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 6, 2008 Share Posted March 6, 2008 <?php echo 'Hello world!'; ?> Use '' for strings with no variables, and "" for variables included in the echo. (DONT QUOTE ME ON ITTTT) Also for like <?php $fun='James'; $fun2="$fun + Bond"; echo "$fun2" ?> that would say James Bond. I think. I'm so tired and have had no coffee. So you pros, dont bother telling me it isn't correct because it might not be. Quote Link to comment Share on other sites More sharing options...
haku Posted March 6, 2008 Share Posted March 6, 2008 Well you learn something new every day I was thinking the same thing in that I didn't know there was a way to serve up php on html pages. I thought they had to be php. What I wonder though, is do $_POST variables still work on these pages? I know that usually trying to $_POST to an html page will cause an error, but does that error not happen when using this method? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2008 Share Posted March 6, 2008 When you tell Apache to process a file via PHP, it doesn't matter what the file extension is. You could easily say AddType application/x-httpd-php .xyz And your apache webserver would process "yourfile.xyz" with the PHP processor. Ken Quote Link to comment Share on other sites More sharing options...
haku Posted March 6, 2008 Share Posted March 6, 2008 Interesting. Thanks! I have a three letter name - maybe I'll serve up my pages on my portfolio site with my name as the extension just for fun. Quote Link to comment 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.