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

Php Tag Name

Usage

Php basics
variable
< ? php echo $txt = 'Hello world!'; ? >
is a containers for storing information. Ex. text equals hello world.
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.
explode()
< ?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ? >
function breaks a string into an array.
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()
function returns a where all matches of a pattern found in the input are replaced with substrings..
typical regular expression
'/^[a-zA-Z ]*$/';
This accepts upper & lowercase letters and spacing.
Php Sessions
session_start()
< ? php session_start(); ?>
begins a session which stores the assigned variables on the server which can be passed from page to page.
session_name
< ?php /* set the session name to WebsiteID */ $previous_name = session_name("WebsiteID"); echo "The previous session name was $previous_name
"; ? >
this method sets the name of your session
session_unset
session_unset();
clears all session variables currently registered.
session_destroy()
session_destroy();
destroys all of the data associated with the current session.
Php cookies
setcookie
$cookie_name = "tommy"; $cookie_value = "15"; setcookie ($cookie_name, $cookie_value, time() + ( 86400 * 30 ), "/" ); // 86400 = 1 day
creates a cookie named tommy with a value of 15 that lasts for 30 days
Php Time
Month
< ? php echo "Today is " . date("F") . "
";?>
returns the month
Day
< ? php echo "Today is " . date("l") . "
";?>
returns day of week
Year
< ? php echo "Today is " . date("Y") . "
";?>
returns 4 digit year.
Hour
< ? php echo "The time is " . date("h"); ?>
12-hour format of an hour with leading zeros (01 to 12)
Minute
< ? php echo "The time is " . date("i"); ?>
Minutes with leading zeros (00 to 59)
Second
< ? php echo "The time is " . date("s"); ?>
Seconds with leading zeros (00 to 59).
am or pm
< ? php echo date(a); ?>
represents time in morning or afternoon and evening format