https://github.com/matronator/pristine-php
Various code snippets and useful functions in PHP
https://github.com/matronator/pristine-php
code-snippets php php-snippets snippets snippets-collection supreme-snippets useful-functions useful-scripts
Last synced: 3 months ago
JSON representation
Various code snippets and useful functions in PHP
- Host: GitHub
- URL: https://github.com/matronator/pristine-php
- Owner: matronator
- Created: 2025-03-31T23:20:51.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-03-31T23:33:12.000Z (3 months ago)
- Last Synced: 2025-04-01T00:27:08.274Z (3 months ago)
- Topics: code-snippets, php, php-snippets, snippets, snippets-collection, supreme-snippets, useful-functions, useful-scripts
- Language: PHP
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Pristine PHP

Collection of useful PHP functions and code snippets.
- [Pristine PHP](#pristine-php)
- [Advanced string Interpolation](#advanced-string-interpolation)
- [Casting](#casting)
- [Folder exists](#folder-exists)
- [JSON to class](#json-to-class)
- [One time file download](#one-time-file-download)## Advanced string Interpolation
> Source: https://stackoverflow.com/a/15410466/13604898
```php
function identity(mixed $arg): mixed {
return $arg;
}
$interpolate = "identity";echo "";
```## Casting
See [Casting.php](Casting.php)
## Folder exists
```php
/**
* 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](JSON2Class.php)
## One time file download
See [OnetimeFileDownload.php](OnetimeFileDownload.php)