“ PHP is an
HTML-embedded scripting language. Much of its syntax is borrowed from C, Java
and Perl with a couple of unique PHP-specific features thrown in. The goal of
the language is to allow web developers to write dynamically generated pages
quickly."
Variables
Declaration:
$variable_name = value;
Example :
<?php
$hello = "Hello World!";
$a_number = 4;
$anotherNumber = 8;
?>
Naming Conventions or Rules for
Variable Declaration :
There
are a few rules that you need to follow when choosing a name for your PHP
variables.
• PHP variables must start with a letter or underscore
"_".
• PHP variables may only be comprised of alpha-numeric
characters and underscores. a-z, A-Z, 0-9, or _ .
• Variables with more than one word should be separated
with underscores. $my_variable
• Variables with more than one word can also be
distinguished with capitalization. $myVariable
Control
Statements :
If
If…else
Nested if
Looping
Statements:
Swith
For
While
Do..while
Operators :
Assignment
Arithmetic
String
String
Handling :
Ø String
creation
Ø String
concatination
Ø String
Position(Strpos)
Ø String
Lowercase to Uppercase(strtoupper()) :
Ø String
Uppercase to Lowercase(strtolower());
Ø String
First letter capitalization: ucwords();
Ø String
breaking or split : explode(‘spl-char/symbol’, $variable);
Ø Spilt
String can be combined by using : implode(‘spl-char/symbol’,$variable);
String
creation :
$myString=”hello world”;
Echo $myString;
String
concate :
Echo $myString.$myString;
String
Position or searching/finding a string
positions:
$numberedString =
"1234567890"; // 10 numbers from 1 to 0
$fivePos = strpos($numberedString, "5");
echo
"The position of 5 in our string was $fivePos";
Lowercase to Uppercase :
$originalString = "String
Capitalization 1234";
$upperCase = strtoupper($originalString);
echo "Old string -
$originalString <br />";
echo
"New String - $upperCase";
Uppercase to Lowercase:
$originalString = "String
Capitalization 1234";
$lowerCase = strtolower($originalString);
echo "Old string - $originalString
<br />";
echo
"New String - $lowerCase";
First letter Captalization:
$titleString = "a title that
could use some hELP";
$ucTitleString = ucwords($titleString);
echo "Old title - $titleString
<br />";
echo "New title - $ucTitleString";
String Spilt :
$rawPhoneNumber =
"800-555-5555";
$phoneChunks = explode("-", $rawPhoneNumber);
echo "Raw Phone Number =
$rawPhoneNumber <br />";
echo "First chunk =
$phoneChunks[0]<br />";
echo "Second chunk =
$phoneChunks[1]<br />";
echo
"Third Chunk chunk = $phoneChunks[2]";
Functions :
Build-in Functions:
- Echo
- Include(“filename.php”);
- Date
- Require(“filename.php”);
User can define Functions:
Function functionname() {
}
No comments:
Post a Comment