Full Version: php "Hello world" ABC question.
UtterAccess Discussion Forums > And More... > PHP, Perl, MySQL and Postgres
Pablito
Hello,
I am doing my first steps with php. I liked this language, but please help me to do first step.
I bought domain.
If I want to put static html files I put them in \web or \public_html folder.
But I want to see how simplest php file works, famous Hello World.
lt;html>
<body><?php
echo "Hello World"; // or print "Hello World";
?></body>
</html>
Well, I save it as hello.php
Where should I put it - in root or in \php folder.
How can I see resulted html file
www.mysite.com/hello.php or how?
My next question willl be about PHP-MySQL construction of dynamic menu. If you can now send me to proper link, I'll be happy.
mishej
This page isn't bad: http://www.webdev-tutorials.com/?p=6
Note the type where "pho" really means "php"!
It is amazing how difficult it is to find a good example to provide. Most assume you are using some product or skip steps.
First - you need to create an .html page that calls PHP as in your example. Save that to your webserver with a name like:
phpExample1.html
Note that you are creating a HTML page that a browser will see. The <?php .... /php> stuff is embedded in the HTML and your web server makes it work (if it is properly configured to support PHP).
CODE
<html>
<head><title>PHP Example 1</title></head>
<body>
  <h2>PHP Example 1</h2><br />
  <?php
    echo "Hello World"; // or print "Hello World";
  ?>
</body>
</html>

If your hosting account is setup for PHP then that is all you should have to write. Upload to your file area and open a browser and navigate to:
http://yourDomainName.com/phpExample1.html
You don't have to create a .PHP file because you have embedded the PHP code within your HTML file by using the <?php> tag.
Hope that helps...
Pablito
Thank you.
Alas, your advise didn't help me directly, but forced me to try variants, and I succeeded!
I think it is somewhere in Hosting setting where set up whether you need to save .html or .php
My hosting provider is hostmonster, so it is equipped with all I need.
Solution was
to save my example as hello.php
put it into public_html folder
and type in browser www.mysite.com/hello.php
In case of saving as html it shows raw php code in View Source.
I am happy now to try to build php files sad.gif)
Still would be tough nut to add MySQL to php. But first step is done!
mishej
Fantastic! Glad you found a solution. It gets easier from this point on.
Good luck on the project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.