http://svnbook.red-bean.com/en/1.6/svn-book.html
Check before working:
| <?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); | |
| } |
| <?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)); | |
| } |
| <?php | |
| // Connect | |
| mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); | |
| $mysqli = mysqli_connect('localhost', 'root', ''); | |
| printf("Connected: %s\n", mysqli_get_host_info($mysqli)); | |
| // Create database | |
| $database = 'mysqli_example'; | |
| $sql = sprintf("CREATE DATABASE IF NOT EXISTS %s", $database); |
http://svnbook.red-bean.com/en/1.6/svn-book.html
Check before working:
| <?php | |
| /** | |
| * Normalize a path. | |
| * | |
| * Usage: path('./one/', '/two/', 'three/'); | |
| * Result: "./one/two/three" | |
| * @param array $parts | |
| * @return string | |
| */ | |
| function path(...$parts) { |
| <?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); |
| <?php | |
| /** | |
| * Check if a value is blank but not zero. | |
| * When you need to accept these as valid, non-empty values: | |
| * - 0 (0 as an integer) | |
| * - 0.0 (0 as a float) | |
| * - "0" (0 as a string) | |
| */ | |
| function is_blank(mixed $value): bool { | |
| return empty($value) && @!is_numeric($value); |
| <?php | |
| /** | |
| * Return a formatted string like vsprintf() with named placeholders. | |
| * | |
| * When a placeholder doesn't have a matching key in `$args`, | |
| * the placeholder is returned as is to see missing args. | |
| * @param string $string | |
| * @param array $kwargs | |
| * @param string $pattern | |
| * @return string |
| <?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 | |
| */ |
| <?php | |
| function tidy_html5($html, array $config = [], $encoding = 'utf8') { | |
| $config += [ | |
| 'doctype' => '<!DOCTYPE html>', | |
| 'drop-empty-elements' => 0, | |
| 'new-blocklevel-tags' => 'article aside audio bdi canvas details dialog figcaption figure footer header hgroup main menu menuitem nav section source summary template track video', | |
| 'new-empty-tags' => 'command embed keygen source track wbr', | |
| 'new-inline-tags' => 'audio command datalist embed keygen mark menuitem meter output progress source time video wbr', | |
| 'tidy-mark' => 0, | |
| ]; |