1. The PHP echo Statement
The echo statement can be used with or without parentheses: echo or echo().Example (from w3 schools) :
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>
Step :
1. Open xampp control panel and start apache
2. Open dreamweaver
4. Save file to local disk c - xampp - htdocs - dashboard
5. Put the filename as php1.php
6. Open the browser and open localhost
7. Put the filename in the link : http://localhost/dashboard/php1.php
*If we stop the apache, the server will stop and page cannot be displayed.
Open with folder
step :
1. Open file local disk c - xampp - htdocs - dashboard - php1.php
2. Right click on the file
3. Open with browser (ex : mozilla firefox)
Output :
View page source :
2.PHP 5 Arrays
Loop Through an Indexed Array
Example :
<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo "<br>";
}
?>
Output :
Add coding on example :
<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo " x=.$x arrlength=.$arrlength";
echo "<br>";
}
?>
Output :
3. PHP FUNCTIONS
PHP Default Argument Value
Example :
<?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50setHeight(135);
setHeight(80);
?>
FILENAME : php3.php
Output :
*setHeight();. No value is set, so it will use the default value that is 50.
Default value statement : function setHeight($minheight = 50)
4. PHP 5 Form Handling
A Simple HTML Form
1. create html file
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
FILENAME : form.html
Output :
2. create php file
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
FILENAME : welcome_get.php
No comments:
Post a Comment