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 | |
function mb_str_split($string, $length = 1, $encoding = NULL) { | |
if (!is_null($string) && !is_scalar($string)) { | |
$type = gettype($string) === 'object' ? get_class($string) : gettype($string); | |
throw new \Exception(sprintf('mb_str_split(): Argument #1 ($string) must be of type string, %s given', $type)); | |
} | |
if ((!is_null($length) && !is_numeric($length)) || $length === '') { | |
$type = gettype($length) === 'object' ? get_class($length) : gettype($length); | |
throw new \Exception(sprintf('mb_str_split(): Argument #2 ($string) must be of type int, %s given', $type)); | |
} |
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
Markdown: | |
[JP Markdown](https://wordpress.org/plugins/jetpack-markdown){.target-blank .rel-nofollow} | |
JavaScript (just before the closing </body> tag): | |
<script> | |
jQuery('.target-blank').attr('target', '_blank').removeClass('target-blank').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class'); | |
jQuery('.rel-nofollow').attr('rel', 'nofollow').removeClass('rel-nofollow').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class'); | |
</script> | |
Post-jQuery HTML: |
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 | |
/** | |
* Localize numeric value using encapsulated NumberFormatter functions | |
* | |
* @param float $amount | |
* @param array $kwargs | |
* @link https://www.php.net/manual/en/numberformatter.format.php | |
* @link https://www.php.net/manual/en/numberformatter.create.php | |
* @link https://www.php.net/manual/en/class.locale.php | |
* @return string|false |
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 | |
/** | |
* Localize datetime using encapsulated IntlDateFormatter functions | |
* | |
* @param IntlCalendar|DateTimeInterface|array|string|int|float $datetime | |
* @param array $kwargs | |
* @link https://www.php.net/manual/en/intldateformatter.format.php | |
* @link https://www.php.net/manual/en/intldateformatter.create.php | |
* @link https://www.php.net/manual/en/class.locale.php | |
* @return string|false |
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 | |
/** | |
* Localize currency using encapsulated NumberFormatter functions | |
* | |
* @param float $amount | |
* @param array $kwargs | |
* @link https://www.php.net/manual/en/numberformatter.formatcurrency.php | |
* @link https://www.php.net/manual/en/numberformatter.create.php | |
* @link https://www.php.net/manual/en/class.locale.php | |
* @return string|false |
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 | |
/** | |
* PHP var_dump() without newline after => . | |
* | |
* NOTE: The only issue is when a string value has `=>\n[ ]+`, it will get converted to `=> ` | |
* @link https://www.php.net/manual/en/function.var-dump.php | |
*/ | |
function vardump($value, $return=FALSE) { | |
ob_start(); | |
var_dump($value); |
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 | |
/** | |
* Filter out non-allowed parameters in the request input and protect parameter values against XSS | |
* | |
* @param int $type INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV | |
* @param array $allowed_params | |
* @link https://www.php.net/manual/en/function.filter-input-array.php | |
* @return array | |
*/ | |
function sanitize_input_array($type, array $allowed_params) { |
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 | |
function array_map_recursive($callback, $array) { | |
$func = function ($item) use (&$func, &$callback) { | |
return is_array($item) ? array_map($func, $item) : call_user_func($callback, $item); | |
}; | |
return array_map($func, $array); | |
} |
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 | |
function mb_substr_replace($string, $replacement, $start, $length=NULL) { | |
if (is_array($string)) { | |
$num = count($string); | |
// $replacement | |
$replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement); | |
// $start | |
if (is_array($start)) { | |
$start = array_slice($start, 0, $num); | |
foreach ($start as $key => $value) |
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 | |
/** | |
* PHP var_export() with short array syntax (square brackets) indented 2 spaces. | |
* | |
* NOTE: The only issue is when a string value has `=>\n[`, it will get converted to `=> [` | |
* @link https://www.php.net/manual/en/function.var-export.php | |
* @param mixed $expression | |
* @param bool $return | |
* @return string | |
*/ |
NewerOlder