You are here: Daniel Dumas » Blog, PHP Tutorials »

PHP and MySQL Basics: Your First PHP Script

PHP and MySQL Basics: Your First PHP Script

Now that you know the basic syntax of PHP, let me congratulate you, congrats! hehe. . You are now ready to learn your very first PHP script.

consider this example on embedding your first PHP script into HTML.

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<!-- This is how you print output in PHP-->

<h2><?php echo "Philippines is a beautiful country!"; ?></h2>

</body>
</html>

copy and save this to your text editor with a .php extension then run it on your localhost..

echo – is a function for printing output.

Remember: you should always end your php statement with a semicolon ( ; ) or else you will get an error, this is true if you have complex php statement, but in the example above it will work fine even if we remove the semicolon at the end of our statement because the closing tag ?> has an implicit semicolon, however it is a good programming practice to end php statement with a semicolon.

you should get this output from your browser..

Remember: White space is not important in php, so…

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<!-- This is how you print output in PHP-->

<h2><?php

echo "Philippines is a beautiful country!";

?></h2>

</body>
</html>

would yield the same output as above.

if you look at the HTML source at your browser you should see something like this. .

<html>
<head>
<title>Hello World!</title>
</head>
<body>

<!- - This is how you print output in PHP- ->

<h2>Philippines is a beautiful country!</h2>

</body>
</html>

Notice that the php tags didnt show up.. it’s because the server understand our php script it processed it and just return to the browser the output which is a valid HTML.

Discussion

  1. [...] bookmarks tagged web development PHP and MySQL Basics: Your First PHP file saved by 4 others     pskim731 bookmarked on 09/23/08 | [...]

Leave a Reply





Spam protection by WP Captcha-Free