Page 45.
This is my Cheat Sheet area to look for items that I'm always forgetting.
- Forms
- Start and End Tags
- Comments
- Variables
Login 02
Login 03
login.php
crypt
Array Examples
Loops
Start and End of PHP
<?php
?>
@ in beginning means to suppress errors
@ $var1=5/0;
Comments
// Comment
# Comment
/* Comment */
Variables
4 scalar (single-value): integer, floating point, string and boolean
2 non-scalar: array and object
7. resources (for use with databases)
8. null
Predefined variables
$_SERVER['SCRIPT_FILENAME']
$_SERVER['HTTP_USER_AGENT']
$_SERVER['SERVER_SOFTWARE']
Constants
define ('NAME', 'value');
define ('TODAY', 'August 28, 2007');
Arithmetic Operators
+ Add
- Subtract
* Multiply
/ Divide
% Modulus
++ Increment
-- Decrement
Concatenation Assingment Operator
$Title .= $Subtitle; # equivalent to
$Title = $Title . $Subtitle;
Number Format
$n=20943;
$n=number_format ($n,2); // 20,943.00
Include Syntax
include ("../config.php");
Included file must have PHP start and end tags. Config.php:
<?php
$host = "localhost";
$user = "automat5_rondahl";
$pass = "historical";
$db = "automat5_ronslibrary";
?>
BOM
If you are using Notepad, it may be as simple as making sure you are saving it using "ANSI" encoding during the Save As process, rather than "UTF-8" (there is a dropdown in the lower left hand corner of the save as box, just below "Save as Type"
Headers and SetCookie Use Notepad and set filetype as Unicode instead of ANSI
Expression Web BOM
Site then Site Settings then Advanced then Language and change Default Page Encoding to US/Western European (ISO)
Form referring to itself:
<form action="<?php echo $PHP_SELF; ?>" method=post>
Hidden Syntax
<input type="hidden" name="num" value="<?php echo $num?>" size ="40"
maxlength="20">
PHP Variable within input box (or in html of a document)
<input type="text" name="isbn_13" value="<?php echo $isbn_13?>" size ="5" maxlength="10"></td>
Loop through returned array and put results in new array
// loop through rows and put in array
$i=1;
while($row = mysql_fetch_row($result)) {
// fill the array
$numfound["num"][$i]=$row[0];
$numfound["sortby"][$i]=$row[1];
$i+=1;
}
Affected Rows
echo 'affected rows = '.mysql_affected_rows();
Count the Rows Returned
mysql_num_rows($result)
Escape Sequences
\" Double quotation marks
\' Single quotation marks
\\ Backslash
\n Newline
\r Carriage return
\t Tb
\$ Dollar sign
Comparative and Logical Operators
== is equal to
!= is not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
! not
&& and
|| or
XOR and not
switch ($variable) {
case 'value1':
// do this
break;
case 'value1':
// do this instead
break;
default:
// do this then
break;
}
isset() returns true for empty string
empty() returns