Recent Notes

Displaying keyword search results 1 - 10
Created by magnum on September 11, 2011 19:46:09    Last update: September 11, 2011 19:46:09
A pair of C functions convert between an Internet address and a string (ASCII): #include <arpa/inet.h> /* * Returns a poin... However , these functions do not support IPv6. The new pair is: #include <arpa/inet.h> /* Convert a Internet ad... Examples: #include <sys/socket.h> #include <netinet/in.h>...
Created by jinx on May 18, 2011 20:09:05    Last update: May 18, 2011 20:09:05
The PHP function file_get_contents reads the entire contents of a file into a string, while the function file reads a file into an array. file_get_contents('filename') is equivalent to implode('', file('filename')) : <?php // reads entire file into array, one elem...
Created by jinx on May 03, 2011 12:11:35    Last update: May 03, 2011 12:12:27
The PHP function is_resource returns TRUE if a variable is a resource. This may come in handy when a function you are calling returns mixed type. For example mysql_query returns TRUE or FALSE for INSERT , UPDATE , DELETE etc., but returns resource or FALSE for SELECT , SHOW , or DESCRIBE . <?php $rows = array(); if ($res = mysql_quer...
Created by jinx on May 03, 2011 11:43:26    Last update: May 03, 2011 11:43:26
The PHP function strval returns the string value of a variable. It does the same thing as casting a variable to string, or automatic conversion where string is expected. Conversion rules: Type String Value Boolean TRUE '1' Boolean FALSE '' (empty string) integer of float string representing the number Array The string 'Array' Object Result of __toString() if defined, error otherwise Resource 'Resource id #n' , where n is a number assigned to the resource. NULL '' (empty string) Example: <?php set_error_handler(function($errno, $errst... Results: bool(true) --------------------- strval: '1'...
Created by jinx on May 02, 2011 12:14:23    Last update: May 02, 2011 12:15:07
The PHP function ctype_digit returns true when all characters in a string is numeric. Use this function only on strings. You get unexpected results with other data types. Example: <?php $a = array("124.34", "00088760", "1.3e5",... Results: string(6) "124.34" ----------------- ctype_d...
Created by jinx on April 29, 2011 15:03:10    Last update: April 29, 2011 15:04:02
The PHP function is_callable verifies that a variable can be invoked as a function. Example: <?php define('F', 'f'); function... Output: var_dump: string(1) "f" is_callable: 1 Calla...
Created by jinx on April 29, 2011 13:43:13    Last update: April 29, 2011 13:44:34
List of functions testing variable type: Function Description is_bool Finds out whether a variable is a boolean is_double Alias of is_float() is_float Finds whether the type of a variable is float is_int Find whether the type of a variable is integer is_integer Alias of is_int() is_long Alias of is_int() is_null Finds whether a variable is NULL is_numeric Finds whether a variable is a number or a numeric string is_object Finds whether a variable is an object is_real Alias of is_float() is_scalar Finds whether a variable is a scalar is_string Find whether the type of a variable is string Test code: <?php class A { } $a = ar... Output: var_dump: int(1) ------------------------- i...
Created by jinx on April 29, 2011 08:38:58    Last update: April 29, 2011 08:39:47
Facts about PHP constants: You can define a PHP constant using the function define . Unlike variables, a constant is used by its symbol without the leading $ . The function constant can be used to get the value of a constant. This can be useful if the name of the constant is given by runtime computation. Class constants are defined with the const keyword. Constants can only be scalar values. Example: <?php // define a constant define('HELLO', '...
Created by jinx on April 28, 2011 14:32:58    Last update: April 28, 2011 14:32:58
Use the is_array function to find out if a variable is array. <?php $a = array( '1' => 'Apple', ...
Created by jinx on April 26, 2011 11:58:33    Last update: April 26, 2011 12:00:40
The PHP function array_unique removes duplicate values from arrays. It takes an optional parameter $sort_flags , which can be one of: SORT_REGULAR : compare items normally (don't change types) SORT_NUMERIC : compare items numerically SORT_STRING : compare items as strings SORT_LOCALE_STRING : compare items as strings, based on the current locale. Example: <?php $a = array( '1' => 'Apple', ... Output: array_unique results: array(3) { [1]=> ...
Previous  1 2 3 4 Next