Skip to content

Various code snippets and useful functions in PHP

Notifications You must be signed in to change notification settings

matronator/pristine-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pristine PHP

Pristine PHP logo

Collection of useful PHP functions and code snippets.

Advanced string Interpolation

Source: https://stackoverflow.com/a/15410466/13604898

function identity(mixed $arg): mixed {
    return $arg;
}
$interpolate = "identity";

echo "<input value='{$interpolate(1 + 1 * random_int())}' />";

Casting

See Casting.php

Folder exists

/**
 * Checks if a folder exist and return canonicalized absolute pathname (sort version)
 * @param string $folder the path being checked.
 * @return mixed returns the canonicalized absolute pathname on success otherwise FALSE is returned
 */
function folder_exist(string $folder): string|false
{
    // Get canonicalized absolute pathname
    $path = realpath($folder);

    // If it exist, check if it's a directory
    return ($path !== false AND is_dir($path)) ? $path : false;
}

JSON to class

See JSON2Class.php

One time file download

See OnetimeFileDownload.php