Tag Archives: core PHP
isset() vs. array_key_exists()
I used to think that if a variable was set to NULL isset() would return TRUE—because NULL is a value to which that variable is set. However, the PHP Manual says this is incorrect. The array_key_exists() function avoids this confusion. … Continue reading
What is stdClass?
The stdClass is a PHP standard predefined class. It is built into PHP. Here are the features of this class: has no methods you create/assign the properties on the fly you can convert arrays to this class you can convert … Continue reading
empty() is similar !$a
The function empty() determines whether a variable is considered to be empty. The following things are considered to be empty: It’s the same list as for the things that make $a evaluate to false in an expression. I think this … Continue reading
The Not Operator ! Used to Check Form Input
The not logical operator ! seems to have a broader interpretation in PHP than in other languages. This makes it possible to use ! to check form input to determine if a value was supplied. According to documentation !$a is … Continue reading
Is this an Int?
Sample function call: WARNING: The original version of function really_is_int fails to return the appropriate value when passed a zero (0). Zero is an integer as are all negative whole numbers. Sample user defined function really_is_int: I used the original … Continue reading
Discover script’s URL (or parts thereof)
Sample code: See $_SERVER in PHP Manual. Sample code: $_SERVER[‘REQUEST_URI’] The URI which was given in order to access this page; for instance, ‘/index.html’. Compare it to $_SERVER[‘PHP_SELF’]. string basename ( string $path [, string $suffix ] ) Given a … Continue reading
Strip HTML from Strings and More
Quote from an interview with Michelangelo van Dam: 15) One function that you like (or which you tend to use frequently) I think one particularly stands out: htmlentities($string, ENT_QUOTES, ‘utf-8’); This function escapes output and ensures that your content is … Continue reading
Uppercase/Lowercase String Functions
strtolower() strtoupper() ucfirst() — capitalize the first letter of the string. ucwords() — capitalize the first letter of each word in the string.