bluethundr Posted October 6, 2009 Share Posted October 6, 2009 Hey guys Brand new to PHP and of course my "Hello World" isn't hello worlding. Any chance you guys could have a look and let me know what the heck went wrong? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8559-1"> <title>Hello, world</title> </head> <body bgcolor="#ffffff"> <?php print "Hello, world"; ?> </h1> </body> </html> Definitely need the clue-by-four here. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/ Share on other sites More sharing options...
MadTechie Posted October 6, 2009 Share Posted October 6, 2009 check list 1. PHP installed and working (all setup etc) 2. check the filename ends with .php NOT .html or .htm try this <?php phpinfo(); ?> in its own file called phpinfo.php you should get a ton of settings info Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931185 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 syntactically it is correct. Is it echoing out the actual code? Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931187 Share on other sites More sharing options...
MadTechie Posted October 6, 2009 Share Posted October 6, 2009 I assumed the code wasn't parsing and the <?php was being treated as a HTML tag, thus not displaying (try viewing source) Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931188 Share on other sites More sharing options...
bluethundr Posted October 6, 2009 Author Share Posted October 6, 2009 Oh this is interesting! I am running on Mac OS X Snow Leopard. This is the first chance I've had to mess around with PHP on it. And the phpinfo() script is not opening the traditional php info page that we all know. It just renders the text from the script in the browser window. But when I type php -version it definitely appears to be installed and working. mazdayasna:apache2 bluethundr$ php -version PHP 5.3.0 (cli) (built: Aug 23 2009 12:55:35) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931197 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2009 Share Posted October 6, 2009 And what URL are you entering in your browser, it should be something like http://localhost/filename.php Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931198 Share on other sites More sharing options...
bluethundr Posted October 6, 2009 Author Share Posted October 6, 2009 I'm actually being a tad lazy and opening the file by going to file -> open in firefox. If I get my php install working correctly I will move my php files to the correct place on the mac and start using them there. But I did manage to find this excellent PHP mac tutorial: http://foundationphp.com/tutorials/php_leopard.php Did everything the article said.. and no love. :'( Same as before. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931209 Share on other sites More sharing options...
Philip Posted October 6, 2009 Share Posted October 6, 2009 I'm actually being a tad lazy and opening the file by going to file -> open in firefox. If I get my php install working correctly I will move my php files to the correct place on the mac and start using them there. But I did manage to find this excellent PHP mac tutorial: http://foundationphp.com/tutorials/php_leopard.php Did everything the article said.. and no love. :'( Same as before. You need to visit it via localhost (while running apache & php) - not just by going to the file. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931211 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 opening it via your browser like that won't do anything, because your browser is not what parses the script. When you go to localhost via your browser, you are making a request to a server (a local server, like when you run apache) just like when you go to a regular website. Apache and php is what actually executes and parses the script. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931213 Share on other sites More sharing options...
bluethundr Posted October 6, 2009 Author Share Posted October 6, 2009 Ok guys, clue-by-four has been applied to yon forehead with great success! So, now opening the phpinfo.php script shows that php is working. However the code snippet I placed before renders a blank page with "Hello, world" showing in the browser title bar. I think we are getting closer. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931220 Share on other sites More sharing options...
Philip Posted October 6, 2009 Share Posted October 6, 2009 Because you set the value of title bar to "Hello, world". As for the text not showing uhh..... Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931221 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 only thing i see wrong with it is you have a closing h1 tag with no opening h1 tag. But that shouldn't stop it from showing it...you sure you're going to the right file? Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931231 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2009 Share Posted October 6, 2009 Worked for me. I'll guess file is not a .php file and/or it is still being opened directly in the browser and not through a URL. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931232 Share on other sites More sharing options...
bluethundr Posted October 6, 2009 Author Share Posted October 6, 2009 What I did was put the file (that I called hw.html for "hello world") in the document root for apache on the mac. The phpinfo.php script is in the same directory and works. I am calling both by going to http://localhost/phpinfo.php and http://localhost/hw.html respectively. I also fixed the <h1> tag, by the way and thanks for the tip. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931233 Share on other sites More sharing options...
bluethundr Posted October 6, 2009 Author Share Posted October 6, 2009 duuuhhhh sorry guys. As I said this is exactly day 1 of my php usage. Going back to the beginning is that I was opening it wrong, and it had the wrong file name. I also had to enable php in apache on my mac. So putting it in the right place, enabling php and giving it the right name worked. thanks again for sticking with me on this. Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931236 Share on other sites More sharing options...
MadTechie Posted October 6, 2009 Share Posted October 6, 2009 check list 2. check the filename ends with .php NOT .html or .htm http://localhost/phpinfo.php and http://localhost/hw.html respectively. ERM.. .html Quote Link to comment https://forums.phpfreaks.com/topic/176631-solved-php-newb-hello-world-broke/#findComment-931237 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.