Unlike Css3 and Javascript which move individual html elements PHP and Mysql move data. PHP moves data into a Mysql database via html forms.Php can can also sanitize and filter data before sending it to Mysql. Here are php functions you will see often:
  1. Mysqli_connect()
  2. PHP Mysqli_fetch_array function
  3. PHP Mysqli close function
  4. Php regular expressions
  5. php echo()
Php Tag Name Php Tags Usage
Php echo < ? php echo( " " ) ? > The echo() function outputs one or more strings.
Php include < ? php include( " " ) ? > takes all the info in one file and copies it into the file that uses the include statement.
implode < ? php $arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr); ?>
returns a string from the elements of an array. example result: Hello World! Beautiful Day!
explode < ? $fruity = 'oranges, pineapple, blueberries'; $array = explode(',', $fruity); foreach ($array as $item) { [oranges, pineapple, blueberries' ]; } ?> function breaks a string into an array.result: [oranges, pineapple, blueberries' ];
rand < ? php rand( "10, 100 " ) ? > Gives you a random number between 10 and 100
Regular Expressions
Preg_match preg_match() The preg_match() function will tell you whether a string contains matches of a pattern.
Preg_replace preg_replace() The preg_match() function will tell you whether a string contains matches of a pattern
typical regular expression '/^[a-zA-Z ]*$/'; This accepts upper & lowercase letters and spacing
check for valid email format < ?php $email = "john.doe@example.com"; ($email, FILTER_VALIDATE_EMAIL) } This check is for email format.Unable to tell if email address exists
testing regular expression against a variable $nameString if(preg_match($regex, $nameString)) { echo("Name string matching with" . " regular expression"); } else { echo("Only letters and white space" . " allowed in name string"); } } $regex equal to '/^[a-zA-Z ]*$/'; which only accepts letters.
Numbers [0-9] This range will accept numbers
Lowercase letters [a-z] This range will accept lowercase letters a thru z.
Uppercase letters [A-Z] This range will accept Uppercase letters A thru Z.
beginning of regular expression ^ starts a regex expression.
end of regular expression $ Ends the expression
Php Session
Php Start a Session < ? php session_start(); ?> begins a session which stores the assigned variables on the server which can be passed from page to page.
Create session variable < ? php $_SESSION [ " favcolor " ]
= "yellow" ; ? >
creates the variable "yellow"
Destroy a Session < ? php session_destroy(): ? > destroys the session.
Unset a session < ? php session_unset(): ? > kills the session
Php Cookies
creating a cookie < ? php setcookie( "" ): ? > A cookie is created with the setcookie. You may set a value, name, and time [duration of cookie].
destroying a cookie < ? php setcookie( "" ): ? > To delete a cookie, use the setcookie()
Setting Cookie values < ? $cookie_name = "user"; $cookie_value = "Alex Porter"; setcookie($cookie_name, $cookie_value, time() + (86400 * 1), "/"); ? > This example sets a cookie for Alex Porter which lasts 1 day.
Php Time
php time function converted to readable time < ? php echo date( ' m / d/ Y
H : i : s', 1541843467 ); ?>
results: 11/10/2018 09:51:07
am or pm < ? php echo (a); ?> represents time in morning
or afternoon and evening format
Hour 24 hour format < ? php echo (H); ?> whole number
between 1 and 24
Hour 12 hour format < ? php echo (h); ?> whole number
between 1 and 12
Minutes with leading zeroes < ? php echo (i); ?> whole number
between 00 and 59
Php Date
Full Month name < ? php echo (F); ?> Ex Feburary
Short Month name < ? php echo (M); ?> Ex Feb
day of month < ? php echo (d); ?> whole number
between 1 and 12
day of week full name < ? php echo (l); ?> Ex Friday
day of week 3 letters < ? php echo (D); ?> ex fri
year last two digits < ? php echo (y); ?> ex 20
year four digits < ? php echo (y); ?> ex 2020