Tuesday 29 January 2019

PHP HTML Form

PHP String Operators:
OperatorDescriptionExampleResult
.Concatenation$str1 . $str2Concatenation of $str1 and $str2
.=Concatenation assignment$str1 .= $str2Appends the $str2 to the $str1

<?php $x = "Hello"; $y = " World!"; echo $x . $y; // Outputs: Hello World! $x .= $y; echo $x; // Outputs: Hello World! ?>

PHP Array Operators

The array operators are used to compare arrays:
OperatorNameExampleResult
+Union$x + $yUnion of $x and $y
==Equality$x == $yTrue if $x and $y have the same key/value pairs
===Identity$x === $yTrue if $x and $y have the same key/value pairs in the same order and of the same types
!=Inequality$x != $yTrue if $x is not equal to $y
<>Inequality$x <> $yTrue if $x is not equal to $y
!==Non-identity$x !== $yTrue if $x is not identical to $y
<?php echo ($age < 18) ? 'Child' : 'Adult'; ?>
<?php $name = isset($_GET['name']) ? $_GET['name'] : 'anonymous'; ?>

PHP Functions for Sorting Arrays:

  • sort() and rsort() — For sorting indexed arrays
  • asort() and arsort() — For sorting associative arrays by value
  • ksort() and krsort() — For sorting associative arrays by key
Round a Fractional Value up or down
ceil(): round a fractional value up;
floor(); round a fractional value down;
rand(); generate some random numbers; //rand(1,10)

PHP Get and Post:
<!DOCTYPE html> <html lang="en"> <head> <title>Example of PHP GET method</title> </head> <body> <?php if(isset($_GET["name"])){ echo "<p>Hi, " . $_GET["name"] . "</p>"; } ?> <form method="get" action="<?php echo $_SERVER["PHP_SELF"];?>"> <label for="inputName">Name:</label> <input type="text" name="name" id="inputName"> <input type="submit" value="Submit"> </form> </body>

Note: $_SERVER["PHP_SELF"] call the php inside this URL;


Running PHP code on Terminal window:
sudo php -f filename.php

Login mysql: mysql -u root -p

Rename file in Linux: sudo mv original_filename new_filename


























No comments:

Post a Comment