If you want something you've never had, you must be willing to do something you've never done!

Powered by Blogger.

Php Programming Tutorial "PHP and HTML" 1

Cerita Semalam Aaz | 10:35 PM | ,

PHP is so well suited for generating HTML sources that you don't even need to have a single line of PHP code in a file to save and call it with the .php extension. Save this HTML source as hello_you.php in the Apache document root:
<html>
<body>
Hello you
</body>
</html>
Call it the same way you have already done, http://localhost/hello_you.php. When you use the .php extension the file will be handled by the PHP interpreter. Although this file contains only HTML, the PHP interpreter will read and process it without a problem. But the php extension will only trigger the PHP interpreter if the file is served by the Web server, otherwise the browser will ask if you want to save or edit it.

Spaghetti

The most common style of PHP and HTML coding is the spaghetti coding style, where both are mixed, like in this hello_you_2.php new version:
<html>
<body>
<?php
echo 'Hello you';
?>
</body>
</html>
Everything inside the <?php ?> tags will be interpreted as PHP code. Whatever is outside these tags will be sent to the client as is. The PHP interpreter will not try to parse it.
Call this last version and take a look at the page source (remember how?). You will see that the source of this page partly generated by PHP code is the same as the page source of the first version without PHP code.
Here is something you should realy understand. The client browser will never see a single line of PHP code. Nothing. Zero. All the PHP code will be interpreted by the server and replaced by whatever text your PHP instructions tell it to, if any. The browser will only get HTML, that is all it can understand besides CSS and Javascript.

1 Responses So Far:

Related Post

 
Back To Top