Skip to content

Instantly share code, notes, and snippets.

@degecko
degecko / slug.php
Last active October 18, 2015 15:42
Generate an alphanumerical slug from a given string
<?php
function slug ($string, $delimiter = '-') {
$string = trim($string);
$string = preg_replace('#[^a-z0-9 ]#i', '', $string);
$string = preg_replace('#\s+#', $delimiter, $string);
return $string;
}
@degecko
degecko / human_fsize.php
Last active October 18, 2015 15:43
Get human readable file size from a number of bytes.
<?php
function human_fsize ($size, $unit = '')
{
if (( ! $unit && $size >= 1 << 40) || $unit == 'TB') {
return number_format($size / (1 << 40), 2) . ' TB';
}
if (( ! $unit && $size >= 1 << 30) || $unit == 'GB') {
return number_format($size / (1 << 30), 2) . ' GB';
@degecko
degecko / url.php
Last active October 18, 2015 15:43
Base URL basic path contructor.
<?php
/**
* Examples of input (assumes $homepage = 'http://site.com'):
*
* Input: url('')
* Return: http://site.com/
*
* Input: url('home')
* Return: http://site.com/home
@degecko
degecko / paginate.php
Last active March 4, 2016 08:18
Pagination helper
<?php
/**
* Pagination helper written for laravel, available for any project.
*
* A couple examples:
*
* [1] $current_page = 1; $total_pages = 1;
* <no output, no pagination needed>
*