Skip to content

Instantly share code, notes, and snippets.

View mdrakibhossainhawlader's full-sized avatar

Rakib Hossain Hawlader mdrakibhossainhawlader

View GitHub Profile
@mdrakibhossainhawlader
mdrakibhossainhawlader / truncate.php
Created July 9, 2018 00:55 — forked from sepehr/truncate.php
PHP: truncate()
<?php
/**
* Truncates string to the specified length.
*
* @param string $string String to truncate.
* @param integer $len Desired length.
* @param boolean $wordsafe Whether to truncate on word boundries or not.
* @param boolean $dots Whether to add dots or not.
*
@mdrakibhossainhawlader
mdrakibhossainhawlader / get_daterange_timestamps.php
Created July 9, 2018 00:54 — forked from sepehr/get_daterange_timestamps.php
PHP: Get corresponding timestamp boundaries of a daterange
<?php
/**
* Generates timestamp bounderies for the passed date range name.
*
* @param string $range Date range name.
*
* @return array
*/
function get_daterange_timestamps($range)
@mdrakibhossainhawlader
mdrakibhossainhawlader / is_timestamp.php
Created July 9, 2018 00:53
PHP: Timestamp validator
<?php
/**
* Checks if a string is a valid timestamp.
*
* @param string $timestamp Timestamp to validate.
*
* @return bool
*/
function is_timestamp($timestamp)
@mdrakibhossainhawlader
mdrakibhossainhawlader / object_to_array.php
Created July 9, 2018 00:53 — forked from sepehr/object_to_array.php
PHP: Recursively cast an object into array
<?php
/**
* Recursively casts an object into array.
*
* @param $object
* Object to cast to array.
*
* @return array
*/
@mdrakibhossainhawlader
mdrakibhossainhawlader / array_map_assoc.php
Created July 9, 2018 00:52 — forked from sepehr/array_map_assoc.php
PHP: Array Map Associative
<?php
/**
* Converts a linear array to its associative equivalent.
*
* @param $array
* Linear array to process.
* @param $function
* Callback name to call against each value.
*
* @return array
@mdrakibhossainhawlader
mdrakibhossainhawlader / rmdir_recursive.php
Created July 9, 2018 00:52 — forked from sepehr/rmdir_recursive.php
PHP: Recursive directory removal
<?php
/**
* Recursively removes a directory.
*
* @param string $path Directory path to remove.
* @param bool $suicide Whether to remove itself or not.
*
* @return void
*/
@mdrakibhossainhawlader
mdrakibhossainhawlader / json_prettyprint.php
Created July 9, 2018 00:50
PHP: JSON prettyprint helper
<?php
/**
* Pretty print JSON objects.
*
* @param array $json JSON array to be printed.
*
* @return string
*/
function json_prettyprint($json)
@mdrakibhossainhawlader
mdrakibhossainhawlader / in_arrayi.php
Created July 9, 2018 00:49 — forked from sepehr/in_arrayi.php
PHP: Case-insensitive in_array()
<?php
/**
* Case-insensitive in_array() wrapper.
*
* @param mixed $needle Value to seek.
* @param array $haystack Array to seek in.
*
* @return bool
*/
@mdrakibhossainhawlader
mdrakibhossainhawlader / mobile_detect.php
Created July 9, 2018 00:49 — forked from sepehr/mobile_detect.php
PHP: Mobile Browser Detection
<?php
/**
* Mobile Browser Detection for PHP.
*/
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro
@mdrakibhossainhawlader
mdrakibhossainhawlader / meta-tags.md
Created July 8, 2018 12:31 — forked from whitingx/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>