PHP Reference Book Blog

PHP Reference: Beginner to Intermediate PHP5

Archive for June, 2011

Jun-17-11

ltrim() and rtrim() function examples

posted by Mario Lurig

The examples presented for both ltrim() and rtrim() are accurate in their results, however the stated functions used is actually trim(). Thus, here are the corrected examples:
ltrim()

$string = "  \n Hello World!";
echo ltrim($string);

Hello World!

echo ltrim($string, " \nA..Ha..z!");
// All capital letters between A and H, all lowercase letters, exclamation point, space, and newline

World!

rtrim()

$string = "!Hello World42! \t\t";
echo rtrim($string);

!Hello World42!

echo rtrim($string, " \t!0..9");
// Range included is all numbers between 0 and 9, tab, space, and exclamation point.

!Hello World

Tags: ,
Jun-17-11

array_flip() function typo

posted by Mario Lurig

A really minor correction. In the first sentence describing the function, it states:

Returns an array with they keys…

It should read:

Returns an array with the keys…

Jun-17-11

MySQL Update Multiple Columns Query

posted by Mario Lurig

While the book only includes a single example on page 117 for the MySQL UPDATE query, it should have also included an example of a multiple column UPDATE. Here is an example:

UPDATE table SET column1=’newvalue’,column2=’nextvalue’ WHERE column3=’value’

Tags:
Jun-17-11

preg_match()

posted by Mario Lurig

(page 156-157)
preg_match()
In the last sentence, it includes some extraneous words: ”number of matches”. It should simply read:

Returns: 1 if matched, 0 if no match, and FALSE on error.