Fundamental of PHP
- PHP code must be enclosed within a block: <?php ……. ?>
- Multiple PHP blocks are allowed in a single document.
- HTML tags can be used within PHP document.
- PHP file can be only executed in web server. It cannot run as a normal HTML file in the local file system.
- End each statement with a semicolon (;)
- Variables start with $ and it is scalable type (no need to declare before used)
- Variable name cannot start with number and it can be any alphanumeric value after the first character.
- echo is function that can print output to browser
- Form is an user interface that accept users input for server to process.
- Form must contains two attributes: action and method. Action attribute specified the script or program that will handle the input. Method is the sending method used (GET or POST). And, a submit button that will do the sending according to these two attributes.
PHP code must be enclosed within a block: <?php ……. ?>
HTML tags do not work within the PHP block. It must use echo function to output them to the browser.
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text 1</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H2>Sub Heading Text 2</H2>";
echo "<p>Paragraph in Sub section</p>";
?>
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text</H2>
<p>Paragraph in Sub section</p>
Multiple PHP blocks are allowed in a single document.
HTML tags can be used within PHP document.
End each statement with a semicolon (;)
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text 1</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H2>Sub Heading Text 2</H2>";
echo "<p>Paragraph in Sub section</p>";
?>
Variables start with $ and it is scalable type (no need to declare before used)
Variable name cannot start with number and it can be any alphanumeric value after the first character.
echo is function that can print output to browser
<?php
$B2B = true;
// $1MDB = "News"; <- Invalid variable start with number
$age = 25;
$name = "Johnson";
$years = 3.5;
echo "Name : ".$name."<br />Age : ".$age;
Form is an user interface that accept users input for server to process.
Form must contains two attributes: action and method. Action attribute specified the script or program that will handle the input. Method is the sending method used (GET or POST). And, a submit button that will do the sending according to these two attributes.
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
No comments:
Post a Comment