PHP Reference Book Blog

PHP Reference: Beginner to Intermediate PHP5

Archive for the ‘Corrections’ Category

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

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.

Dec-21-09

fwrite() has a Double Tip that is Misplaced

posted by Mario Lurig

On page 131, the fwrite() function has a TIP that reads:
 
To read the entire file into a string, use the function filesize().

// file.txt contains the sentence: Hello World!
$filename = 'file.txt';
$file = fopen($filename, 'r');
$string = fread( $file, filesize($filename) );
var_dump($string);
// file.txt now contains at the end: Hello World!

You’ll notice that this is the same tip as fread() and doesn’t belong. It should be considered ‘removed’.

Dec-20-09

Index: array_combine() array_key_exists()

posted by Mario Lurig

Some quick corrections for the Function Index:

pg. 162

preg_match_all: 157-158

pg. 161

array_combine: 73
array_key_exists: 79-80