Set Timezone using PHP

Set Timezone using in PHP
<?php
date_default_timezone_set(‘America/Toronto’);
echo date(“F j, Y, g:i a”);
?>
For more timezones please find this URL: http://php.net/manual/en/timezones.php

PHP script for Fibonacci number

PHP script for first 20 Fibonacci numbers
<?php
$count = 0 ;
$c1 = 0;
$c2 = 1;
echo $c1.” , “;
echo $c2.” , “;
while ($count < 20 )
{
$c3 = $c2 + $c1 ;
echo $c3.” , “;
$c1 = $c2 ;
$c2 = $c3 ;
$count = $count + 1;
}
?>

<?php
/* Find number odd or even */
$num = 32;
$even = ($num % 2 == 0);
$odd = ($num % 2 != 0);
?>

Cursor suddenly jumping from textarea

If we use typejs in our document this type of issue will occur find below code to fix.
$(“.textarea”).bind(‘keypress’, function(e) {
if(e.which == 32){
var textarea_val = $(“.textarea”),
val_ask = textarea_val.val();
textarea_val.focus().val(“”).val(val_ask);
}
});

HTTPS redirection code for htaccess

/*Total website redirect to HTTPS*/

ExpiresActive On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]


/*Redirect specific page to HTTPS*/

ExpiresActive On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} /page_path/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

array_slice function for array pagination

array_slice function we will use for array pagination to get some part of array

$items = array(1,2,3,4,5,6,7,8,9,10);
$limit = 3;

$qty_items = count($items);
$qty_pages = ceil($qty_items / $limit);

$curr_page = isset($_GET[‘page’]) ? $_GET[‘page’] : 1;
$next_page = $curr_page < $qty_pages ? $curr_page + 1 : null;
$prev_page = $curr_page > 1 ? $curr_page – 1 : null;

$offset = ($curr_page – 1) * $limit;
$items = array_slice($items, $offset, $limit);

$items // Array of elements

$offset // how many elements leave at the time of fetching

$limit //get number of elements from array

Pagination code

for($i = 1; $i <= $qty_pages; $i++){

echo $i;

}

ceil() function return integer number.