Syntax
PHP is a useful coding language. It will simplify your life in many ways. When you use PHP, the page extension must be .php instead of .htm! Here are three different ways to insert PHP in your page:
<?
/* php code */
?>
<?PHP
/* php code */
?>
<?php
/* php code */
?>
To display a text, you can do it like that:
<?php echo "PHP rocks my socks." ?>
Copy and paste the code above, save it as test.php and upload it to your server. Go to the page url: if you can read "PHP rocks my socks.", it means your server supports PHP, congrats! Pay attention to apostrophes:
<?php echo "Hey it's me" ?>
In the code above, you can leave the ' since you're using ", however:
<?php echo 'Hey it\'s me' ?>
See? You must add \ before each apostrophe if you're using '.
As in HTML, you can insert invisible comments in the source.
// Intructions here
// Another line
But if you use //, you will have to re-add them at each line. There's an other solution:
/* This is the first line
And this is the second one! */
See? This code can be used on 2 or more lines.
Sponsors
Leave a Comment
Works? Doesn't work? Other tips? Please leave a comment! :)