PHP check string exist in string

November 17, 2014

The correct way to write the statement to check if string contains specific words is use strpos function. Strpos is used to find the occurrence of one string inside other. Note that the use of !== false is deliberate; strpos returns either the offset at which the needle string begins in the haystack string, or […]

PHP dealing with commas in CSV data

November 12, 2014

Look carefully the data, there are multiple commas ‘,’ inside the address field. When transform the data to array, the output will be each commas separated in one array value. Example: (wrong way) Don’t attempt to do this with a regular expression. Just use str_getcsv()! The third parameter informs str_getcsv() to look for quote-enclosed fields. […]

PHP convert none png image to png format using GD

September 25, 2014

Based on what kind of image it is you could select the correct function to open the file. Then, you just need imagepng() to convert. Example:

PHP resize image using ratio

September 25, 2014

To maintain the aspect ratio of your original image, calculate the factor by which you have to resize the image in the vertical and horizontal direction. Example, resize image to 1920 max width or max height

PHP get image width & height

September 25, 2014

To get the width and height of the image use getimagesize(path_name), this function returns the array which contains the height, width, image_type constant and other image related info. By the following code you can achive that. See also PHP resize image using ratio

PHP delete file in directory

September 15, 2014

If to delete a single file, use the unlink() function. Unlink can safely remove a single file. That function will delete what you pass it as a parameter. For example, delete single file Delete multiple file in a directory, use loop:

PHP check if image file exists

September 12, 2014

File_exists does something weird, it does not say if a file exists, it says if path exists. So, to check if it is a file then you should use is_file together with file_exists to know if there is really a file behind the path, otherwise file_exists will return true for any existing path. Example:

PHP MySql query for random record from database table

September 5, 2014

The simplest way of selecting random rows from the MySQL database is to use “ORDER BY RAND()” clause in the query. Example:

PHP array random value array_rand

September 5, 2014

Returns a set of keys for random entries of array. If you want to pick all entries in a randomized fashion you should be using: ref: http://stackoverflow.com/questions/18046630/php-array-rand-random-value/25678043#25678043

AWS Use of undefined constant CURLE_COULDNT_RESOLVE_HOST

August 22, 2014

It appears that you are missing curl. If you are linux you can usually install it via the package manager package would be named something similar to php-curl. If windows, enable the curl extension in php.ini To check if curl installed in php, you may create a phpinfo.php file in your server root and run […]