How to check if the CURL extention is installed and compiled with PHP

Add this line of code to a PHP script var_dump(curl_version()); If there was a error similar to this Fatal error: Call to undefined function curl_version() or no results was shown, it means that CURL is not installed.

March 22, 2018 · 1 min · 37 words · icarnaghan

How to check in Controller which validation rule failed in cakePHP

Put the code below in your controller and replace the model name with the appropriate model name against which to check. $errors = $this->ModelName->invalidFields(); The above code will return a array containing the validation rules that failed. To read more about validating data in cakePHP click here

March 22, 2018 · 1 min · 47 words · icarnaghan

How to check which version of PHP you are running on Linux

NOTE: Tested on Centos 4 & 5 and Ubuntu 9.04 In the command line type in the following command to get all PHP information and configurations php -i To get the Version number use the following command php -v Or this command: php -i | grep 'PHP Version'

March 22, 2018 · 1 min · 48 words · icarnaghan

How to compare two dates using PHP

First we need to convert the two dates to UNIX Timestamps using the PHP function strtotime Then we can compare the two dates in anyway we wish, in the example below I’m checking that the first date is older than the second date $date1 = '1999-10-11'; $date2 = '2010-10-11'; $firstDate = strtotime($date1); $secondDate = strtotime($date2); if($firstDate < $secondDate){ echo 'First date is older'; }else{ echo 'Second date is older'; }

March 22, 2018 · 1 min · 70 words · icarnaghan

How to convert a MySQL Datetime field to a Unix Timestamp using PHP

In the example you’ll find a handy PHP function that will do the conversion. <?php $DATETIME = '2010-04-22 19:54:38'; echo convertDateTime($DATETIME); /* * This function converts a mysql datetime to a unix timestamp * The format should be "YYYY-MM-DD HH:MM:SS" * * @param $datetime string Contains the DATETIME value * @return UNIX TIMESTAMP */ function convertDateTime($datetime) { list($date, $time) = explode(' ', $datetime); list($year, $month, $day) = explode('-', $date); list($hours, $minutes, $seconds) = explode(':', $time); $UnixTimestamp = mktime($hours, $minutes, $seconds, $month, $day, $year); return $UnixTimestamp; } ?> First we divide the date from the time and then break up the date into year, month and day variables. After that we break the time up into hour, minute and second and then we create a Unix Timestamp using the mktime PHP function.

March 22, 2018 · 1 min · 131 words · icarnaghan

How to convert all $_POST or $_GET values to Integers

By using the built-in PHP functions array_map and intval. array_map = Applies the callback to the elements of the given arrays, this applies the function for each value of an array (PHP 4 >= 4.0.6, PHP 5) intval = Get the integer value of a variable (PHP 4, PHP 5) Examples: {codecitation style=“brush: PHP;”} $post_int = array_map(‘intval’, $_POST); //Converting every post value to integer $get_int = array_map(‘intval’, $_GET); //Converting every get value to integer {/codecitation}

March 22, 2018 · 1 min · 75 words · icarnaghan

How to convert all text to uppercase using CSS

If you have text within a div tag that you want to convert to Uppercase you can achieve this using the CSS text-transform property that was introduced in CSS1 E.g. You want to convert <div> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div> to <div> LOREM IPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY. </div> to do this we assign the text-transform: uppercase; css property to the div tag’s styling ...

March 22, 2018 · 1 min · 83 words · icarnaghan

How to convert px to ems

Use the following formula to calculate px’s to ems 1 ÷ browser default font size x pixels to convert A browsers default font size ussually is 16px so if you want to convert 12px’s to ems do the following 1 ÷ 16 x 12 = 0.75 ems

March 22, 2018 · 1 min · 47 words · icarnaghan

How to convert px to percentage

Use the following formula to calculate px’s to percentage pixels to convert ÷ browser default font size x 100 = percentage A browsers default font size ussually is 16px so if you want to convert 12px’s to percentage do the following 12 ÷ 16 x 100 = 75 %

March 22, 2018 · 1 min · 49 words · icarnaghan

How to create a 301 redirect to redirect a non www URL to a www URL using the .htaccess file

Create a .htaccess file within your web directory where all your website files are located Add the following code to it RewriteEngine On RewriteCond %{HTTP_HOST} ^yourdomain.com$ RewriteRule ^/?(.*)$ "http\:\/\/www\.yourdomain\.com\/$1" [R=301,L] Replace yourdomain.com with your website address This will ensure that when yourdomain.com is entered in the address bar it will redirect to www.yourdomain.com, this will help so that search engines won’t pick up duplicate content for your website

March 22, 2018 · 1 min · 68 words · icarnaghan