Skip to content

Instantly share code, notes, and snippets.

@guimadaleno
guimadaleno / acronym.php
Created September 1, 2022 15:33
Form acronyms from a string
<?php
/**
* Form acronyms from a string
* @param string $str
*/
function acronym ($str)
{
@guimadaleno
guimadaleno / create-slug.php
Created September 1, 2022 15:32
Create slug from string
<?php
/**
* Replaces spaces between string by hyphens
* @param string $str
* @return string
*/
function create_slug ($str)
{
@guimadaleno
guimadaleno / strip-accents.php
Created September 1, 2022 15:31
Strip all accents characters from strings
<?php
/**
* Removes accents from a string
* @param int $str
* @return string
*/
function strip_accents ($str)
{
@guimadaleno
guimadaleno / random-password.php
Created September 1, 2022 15:29
Generate random password
<?php
/**
* Generate a random password
* @param int $length
*/
function random_password ($length = 8, $chars = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789")
{
@guimadaleno
guimadaleno / is-valid-url.php
Created September 1, 2022 15:28
Is valid URL function
<?php
/**
* Test if URL is valid
* @author SpikeZ
* @param string $str
* @return bool
*/
function is_valid_url ($uri)
@guimadaleno
guimadaleno / date-comparison.php
Last active September 1, 2022 15:28
Small date comparison functions
<?php
/**
* Test if date is equal
* @param string $date1
* @param string $date2 (default today timestamp)
* @param string $format (default d/m/Y)
* @return bool
*/
@guimadaleno
guimadaleno / indent-json.php
Created September 1, 2022 15:21
Indent JSON string
<?php
/**
* Indent JSON strings
* @param string $str
* @return string json
*/
function indent_json ($str)
@guimadaleno
guimadaleno / convert-hex-rgba.php
Created September 1, 2022 15:21
Convert HEX color to RGB(A)
<?php
/**
* Converts HEX color code to RGB(A)
* @param string $color
* @param int $opacity
* @return string
*/
function hex2rgba ($color, $opacity = false)
@guimadaleno
guimadaleno / format-bytes.php
Created September 1, 2022 15:19
Format bytes (int) to KB, MB, GB...
<?php
/**
* Format bytes to KB, MB, GB...
* @param int $bytes
* @param int $precision
* @return string
*/
function format_bytes ($bytes, $precision = 2)
@guimadaleno
guimadaleno / average-median-array.php
Created September 1, 2022 15:18
Calculate average and median of array values
<?php
/**
* Calculate average of array values
* @param array $array
* @return int $average
*/
function array_average ($arr)
{