PHP Prepare IN statement from array
April 14, 2014
Some of us may not know that when preparing mysql IN statement, the string inside the IN() need to be single quoted and separated by comma. Example: Unless it is a number. Otherwise double quote or no quoting the string will give you error. Example: WHERE categories IN (“red”, “blue”, “green”) To prepare IN statement […]
PHP how to destroy session id
April 14, 2014
The unset() function is used to free the specified session variable: or better catch
PHP check if a string is JSON
April 7, 2014
Simple method will be: This method doesn’t rely on heuristics, uses native php functionality, and is about as future-proof as you’re gonna get; it just tells you straight up whether there were any errors in decoding the string.
PHP html entity decode UTF-8 encoding
April 7, 2014
For a multilanguage site, using html_entity_decode without encoding type is risky to your website as in some cases, the translated language show weird characters. In version of php prior to 5.4.0, if encoding omitted, default encoding value is ISO-8859-1, and UTF-8 auto set only from PHP 5.4.0 Constant Name Description ENT_COMPAT Will convert double-quotes and […]
PHP obtaining the next month, date-string parser
March 26, 2014
The correct way of obtaining next month correctly is by using “first day of next month” or using “last day of next month”. In normal case, user next month in php to obtain next month value doesn’t work as expected, but it skips to month after next month, Example: Output will be: March. Which suppose […]
php mktime you should be using the time function instead
February 20, 2014
As of PHP 5.1, when called with no arguments, mktime() throws an E_STRICT notice: use the time() function instead Reference: http://php.net/manual/en/function.mktime.php
PHP get next month first day and remaining days to this date
February 20, 2014
Below method is tweaked to take account of December. This method is leap-year safe. The day count must include floor(). From above mktime calculation, not only get the number of days, we can count the hours and minutes till next month first day. Example:
php in_array check for multiple values
February 19, 2014
It depend on how many values to check using in_array. If more than two, better way is loops through array and runs an in_array of it on the checking array. Returns true once something is found, else it returns false. If only two, probably can use if: Reference: http://stackoverflow.com/questions/7542694/in-array-multiple-values
PHP convert an object to an array
February 13, 2014
For single dimensional array (array) $object works fine. Multi dimension object to array consist of private and protected members. Example single dimensional: All objects to converted to associative arrays: Reference from here
PHP check whether image exists on remote URL
February 12, 2014
The simplest and fastest way is to use curl if your host supports curl.
Recent Comments