Corrections – PHP Reference Book Blog https://phpreferencebook.com/ PHP Reference: Beginner to Intermediate PHP5 Sun, 01 Oct 2017 17:21:19 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.13 ltrim() and rtrim() function examples https://phpreferencebook.com/corrections/ltrim-and-rtrim-function-examples/ Fri, 17 Jun 2011 21:45:42 +0000 https://phpreferencebook.com/?p=438 Continue reading ltrim() and rtrim() function examples]]> 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

]]>
array_flip() function typo https://phpreferencebook.com/corrections/array_flip-function-typo/ Fri, 17 Jun 2011 21:32:06 +0000 https://phpreferencebook.com/?p=435 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…

]]>
preg_match() https://phpreferencebook.com/corrections/preg_match/ Fri, 17 Jun 2011 21:09:34 +0000 https://phpreferencebook.com/?p=428 (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.

]]>
fwrite() has a Double Tip that is Misplaced https://phpreferencebook.com/corrections/fwrite-double-tip-misplaced/ Mon, 21 Dec 2009 12:00:09 +0000 https://phpreferencebook.com/?p=346 Continue reading fwrite() has a Double Tip that is Misplaced]]> 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’.

]]>
Index: array_combine() array_key_exists() https://phpreferencebook.com/corrections/index-preg_match_all-array_combine-chdir-array_key_exists/ Sun, 20 Dec 2009 08:04:18 +0000 https://phpreferencebook.com/?p=337 Some quick corrections for the Function Index:

pg. 162

preg_match_all: 157-158

pg. 161

array_combine: 73
array_key_exists: 79-80

]]>
array_key_exists() Function Index Correction https://phpreferencebook.com/corrections/array_key_exists-function-index/ Tue, 03 Feb 2009 03:38:43 +0000 https://phpreferencebook.com/?p=101 Thanks to John for submitting this correction!

In the Function Index (pg. 161), array_key_exists() is listed as page 82. However, it is actually on page 79.

Feel free to submit a correction yourself if you find any!

]]>
Print_r optional parameter correction https://phpreferencebook.com/corrections/print_r-return-parameter/ Wed, 14 Jan 2009 05:21:35 +0000 https://phpreferencebook.com/?p=81 Continue reading Print_r optional parameter correction]]> (pg. 38)

In the book, the print_r() function is described as follows:

print_r($variable)

Output the contents of $variable . Typically used to display the contents of an array.

However, there is also an optional flag for the print_r() function that makes the function return the output rather than printing it to the screen. Therefore, the section of the book should be amended as follows:

print_r($variable [,return])

return – [optional] $boolean default: FALSE, print output
Output the contents of $variable. Typically used to display the contents of an array. If return is set to TRUE, print_r() returns the output rather than displaying it, such as when storing it in a variable.

]]>
mysql_result() correction https://phpreferencebook.com/corrections/mysql_result-correction/ Fri, 02 Jan 2009 01:25:40 +0000 https://phpreferencebook.com/?p=37 Continue reading mysql_result() correction]]> (pg. 123)

The function has the following correct syntax:

mysql_result(resource, row[, column])

However, in the explanation paragraph, 2nd sentence, it uses the term field erroneously instead of the term column. It should read as follows:

If column is specified instead of the value of the
first column, the specified column is retrieved (can be referenced by number
starting with 0 or by name/alias).

It’s the little things, like changing the term used to be clearer to the reader and forgetting to update everything.

]]>
RegEx PERL Compatible Character Class \w https://phpreferencebook.com/corrections/backslash-w/ Sat, 31 May 2008 02:11:43 +0000 https://phpreferencebook.com/?p=13 (pg. 150)

Book version:

\w – Letter (a-z, A-Z)

Correct version:

\w – Letter, Digit, Underscore [a-zA-Z0-9_]

This is similar to the syntax for alphanumeric: [:alnum:]

]]>
$_SERVER[‘QUERY_STRING’] in Global Variables https://phpreferencebook.com/corrections/_serverquery_string/ Wed, 30 Apr 2008 04:50:37 +0000 https://phpreferencebook.com/?p=8 Continue reading $_SERVER[‘QUERY_STRING’] in Global Variables]]> (pg. 33)

The description in the book reads:

$_SERVER[‘QUERY_STRING’] – The current scripts path

This description is the same as the entry above, because I made a bad edit (copy/paste for formatting). The correct description would be as follows:

$_SERVER[‘QUERY_STRING’] – The current query string (without the question mark)

The example is correct and accurate, and luckily this is painfully obvious thanks to the name of the key QUERY_STRING in the $_SERVER array.

]]>