... of PHP
and MySQL, to make static HTML pages dynamic. The labs and exercises have been tested by myself, Marko, and our
students. I think you will find this “by Example book a helpful and complete ... versions and/ or custom covers and content particular to your business, training goals,
marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government ...
2.4.1. PHP on the Command Line
UNIX and Linux users are normally more familiar with working at the command line than Windows or Mac users.
Executing PHP at the command line requires that you...
... variable that will be assigned to the new
variable; for example, $ref = & $old;. See Example 4.14 and it’s output in Figure 4.17.
Example 4.14.
<html><head><title>References</title></head> ... $husband = "Honey"; // Assign the value "Honey" to $husband
2 $son = & $husband; // Assign a reference to $son.
// Now $son is a reference or alias
// for $husband. ... him $husband, and his Mom calls him
$son.
<br />";
4 $son = "Lazy"; // Assign a new value to $son;
// $husband gets the same value
5 print "Now his wife and mother...
... $x and $y and $z;
echo "$x and $y and $z <em>yields</em> " .
(int)$result .".\n<br />";
4 $result = ($x and $y and $z);
echo "($x and $y and ...
[2]
The single & is a bitwise ANDand evaluates both of its operands even if the first one is false. The | is the bitwise OR
and evaluates both operands as well. See “Bitwise Operators” ... logical operators are the logical AND, logical OR, and logical NOT. The symbol for AND is &&, the symbol
for OR is ||. The English version for && is andand for || is or. The only difference...
... uppercase “A” is represented as decimal 65 and an uppercase “B” as decimal 66, and so on. On
the other hand, a lowercase “a” is 97 and a lowercase “b” is 98, and so on. If you compare “A” to “a,” ... “Files and Directories.”
6.2.2. Formatting Numbers and Money
Putting commas or spaces in numbers or printing out the dollar value of money causes a number to become a string and
can be handled ... ( resource handle, string format [, mixed args [,
mixed ]] )
%
Example:
sprintf($filehandle, "%04d-%02d-%02d", $year, $month, $day);
For more information on streams and files,...
... entities, special symbols starting with an ampersand and terminated with a semicolon; for example, the < and >
symbols are written as < and >. If the user enters text that contains ... nested loops is to display data in rows and columns where one
loop handles the rows and the other handles the columns. The outside loop is initialized and tested; the inside loop then
iterates ... size of the array; for example, if an array has five values, its last index value would be four. See Example 8.5.
If the array has been assigned both a key and a value, and the key is a string,...
...
$colors=array("red","green","blue","yellow"); $random= array_rand($colors);
// Returns a random color $random= array_rand($colors, 2); // Returns two
random colors print $colors[$random_keys[0]]; print $colors[$random_keys[1]]; ... it a starting random point) the random number as it is now done
automatically.
Format
random_key= array_rand ( array_name ); array_of_keys = array_rand( array_name,
integer);
Example:
$colors=array("red","green","blue","yellow"); ... Output from Example 8.34.
8.1.12. Randomizing an Array
Randomizing an array means that you can select the keys or the values in random order.
Randomizing the Keys
The array_rand() function...
...
Arrays !and! Strings
explode()
Splits!up!a!string!by!a!specified!delimiter !and! creates !and!
array!of!strings!(see!page!276).
implode()
Glues!the!elements!of!an!array!together!by!some!delimiter !and!
creates!a!string!(see!page!276). ... 8.43. Selecting two random elements from an array. Output from Example 8.36.
!
Figure 8.44. Refreshing the screen for two more random elements.
Shuffling a Numeric Array (Randomizing the Values) ... the random number generator (give it a different starting point) with
srand(), but now that is done automatically. To randomize a selected number of elements of an array, see the
array_rand()...
... quotes and backslashes. The PHP script in
Example 10.5 demonstrates how the stripslashes() function handles this input.
Figure 10.10. The user enters quotes and backslashes.
&
Example ... require() and include(), the require_once() and include_once() statements, respectively,
include and evaluate the specified file during the execution of the script, but require_once() and
include_once() ... the URL and fails.
&
&
10.3.7. Form Parameters and the Long (Old) Style
As of PHP 5.0.0, these long predefined variables can be disabled with the register_long_arrays directive and
are...
...
Grant%read,%write, %and% execute%to%the%owner,%read %and% execute%to%the%group %and%
the%others%(world).
2
Set%all%to%read,%write, %and% execute%on%all%files %and% in%the%current%working%
directory.
3
User%gets%read %and% write,%group %and% others%get%read. ... Chapter 11, “Files and Directories,” we talk about files and how to
open and close them, read from them and write to them, copy them, lock them, upload them, compress them, and more,
all from ... the filehandle, PHP provides the fopen() function. This function opens a file and returns a filehandle, and
if it fails, returns false. It normally takes two arguments: a filename and a mode,...
... upbeat. $new_string=preg_replace("/(Peace) and (War)/i", "$2 and $1",
"Peace and War");
$new_string: "War and Peace" $new_string=preg_replace("/5/e", ... site and causing havoc.
The is_writable() (or is_writeable) function returns true if a file exists and is writable, and false if it is not.
Format
bool is_writable ( string filename )
%
Example: ... PHP errors and printing your own. Output from Example 11.21.
11.2.10. Creating, Copying, Renaming, and Deleting Files
Table 11.8 lists functions for creating, copying, renaming, and removing...
... class. The symbols \d and \D represent a single digit
and a single nondigit, respectively (the same as [0-9] and [^0-9]); \w and \W represent a single word character
and a single nonword character, ... pattern love, and would match glove, clove, or love, but not
clover. /\blove\b matches a word beginning and ending with the pattern love, and would match only the word
love.
Example 12.16. ... text is
enclosed in parentheses and prepended with ?<=. The text is not captured as in the previous examples, but is only used
as criteria for the search.
Example 12.41.
_29*!a>*6b!
(The...
... rows in set (0.00 sec)
The ANDand OR Operators
AND and OR operators are used in a WHERE clause to further qualify what data you want to select from a table. The AND
operator tests one or more ... Linux, Macintosh, and Windows. PHP and MySQL fit very well together. They are
both reasonably easy to use, fairly scalable and reliable and have a good set of features for small- and medium-sized ...
connection, version, how to encrypt and encode strings, display date and time, and so on. Examples follow the table.
Table 13.3. MySQL Functions
Function
Example
What&It&Returns
database()...