An Introduction to PHP
This Tutorial gets you started with PHP Programming.
PHP is a server-side programming language, which is used to preprocess data such as:
- text
- html
- css
Note. PHP is not a replacement for html or css, instead it is used together, to create "dynamic" websites. It is also used to make calculations, and take decisions if a given condition is met.
How it works
You either need your own server such as Apache, with php installed. Or a host which has support for PHP on their server.
I would suggest that beginners simply buy a domain name, and some hosting space, an example of such a host would be one.com.
Your First Page
Most examples will start out with the build-in function called "echo", as will this. Lets start by outputting some text to the browser, using echo.
<!DOCTYPE html>
<html lang="en">
<head>
<!--This is a HTML comment-->
<title>My first Website</title>
</head>
<body>
<?php
echo '<p>My first Website.</p>';
?>
<!--This is a HTML comment-->
</body>
</html>As seen in the above example, we start by telling the server that we are going to write php. Every server which has support for php understand, "<?php" as start tag, and "?>" as end tag. You can also use the echo function to output the whole page, as seen below.
<?php
echo '<!DOCTYPE html>
<html lang="en">
<head>
<!--This is a HTML comment-->
<title>My first Website</title>
</head>
<body>
<p>My first Website.</p>
<!--This is a HTML comment-->
</body>
</html>';
?>The above isn't really useful, so lets start using php for some useful tasks in the next few tutorials.
Past: An Introduction to HTML Next: Paragraphs and Headings in HTML