This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Converts string to SEO-friendly form (lowercase hyphenated alphanumeric words) | |
* | |
* @param $string | |
* @return string | |
*/ | |
function seoUrl($string) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns initial letters of all words from all arguments. | |
* | |
* @param $string $str,... | |
* @return string | |
* @example initials('Johann Sebastian', 'Bach') => 'JSB'. | |
*/ | |
function initials() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Geocodes an address using Google API (limit 2500/day). | |
* | |
* @param string $address - Address to be geocoded. | |
* @param string [$region=gb] - Region results are to biased to. | |
* @return object {lat, lon, status, address}. | |
*/ | |
function geocode($address, $region='gb') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cleans up posted data - trims texts & converts empty fields to null. | |
* | |
* @param mixed[] $post POST data to be cleaned. | |
* @return mixed[] Cleaned-up POST data. | |
*/ | |
function clean($post) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Encrypts object to be stored secure from prying eyes (uses AES-256 ECB). | |
* | |
* @param object $sourceObj Object to be encrypted. | |
* @param string $key Key to use for encryption. | |
* @return string Encrypted object. | |
*/ | |
function objEncrypt($sourceObj, $key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Truncates text to given length with suffixed ellipsis. | |
* | |
* @param string $text Original text string. | |
* @param int $length Length to truncate to. | |
* @param bool [$wholeWords=true] Whether to truncate back to whole words. | |
* @return string Truncated string. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns how long ago something happened in the past, showing it as | |
* 'n' seconds / minutes / hours / days / weeks / months / years ago. | |
* | |
* For periods over a day, it rolls over at midnight (so doesn't depend on | |
* current time of day), and it correctly accounts for month-lengths and | |
* leap-years (months and years rollover on current day of month). | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Encodes multi-byte Unicode string into utf-8 multiple single-byte characters | |
* (BMP / basic multilingual plane only). | |
* | |
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars. | |
* | |
* Can be achieved in JavaScript by unescape(encodeURIComponent(str)), | |
* but this approach may be useful in other languages. | |
* | |
* @param {string} unicodeString - Unicode string to be encoded as UTF-8. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]. | |
* As per RFC 4648, no newlines are added. | |
* | |
* Characters in str must be within ISO-8859-1 with Unicode code point <= 256. | |
* | |
* Can be achieved JavaScript with btoa(), but this approach may be useful in other languages. | |
* | |
* @param {string} str ASCII/ISO-8859-1 string to be encoded as base-64. | |
* @returns {string} Base64-encoded string. |
OlderNewer