Skip to content

Instantly share code, notes, and snippets.

@christoferd
christoferd / RoundDown2DemialPlaces.php
Last active February 13, 2018 21:41
PHP: Round a number down to two decimal places
/**
* Custom function to round down to the nearest lowest number at 2 decimal places.
* e.g: 1.006 rounds down to 1.00
* Warning: Do not use PHP_ROUND_HALF_DOWN;
* round(0.006, 2, PHP_ROUND_HALF_DOWN) does not round down to 0
*
* @param $value
* - Must be numeric
* - Must be a positive value
* @return float
@christoferd
christoferd / wordWrapAtCharacter.php
Last active January 2, 2016 13:49
String/Text Word Wrap at a certain character. First created to wrap a long CSV list.
function wordWrapAtCharacter($str, $minWidth = 200, $char = ',', $lineBreak = "\n")
{
// prev pos
$marker = 0;
// char pos
$pos = false;
if($minWidth+$marker < strlen($str))
{
$pos = strpos($str,$char,$minWidth+$marker);
}
@christoferd
christoferd / gist:7394561
Last active December 27, 2015 21:49
Create plain Text table from Array, or Array of Arrays. Great for dumping database table data to text only logs or display. Supports vertical single record display, and multi row (array of arrays) display. - 11-Nov-2013 Added Hanlde Empty Array
/**
* Create plain Text table from Array, or Array of Arrays.
* Great for dumping database table data to text only logs or display.
* @use String::textTableFromArray($myArrayOfArrays,'My Multi Row Table',true); // multiple records/array
* ArrayHelper::textTableFromArray($simpleKeyValArray,'A Single Record',false); // single row, vertical view
* @requires String::humanize() ... or just remove/override it.
*
* @param $arr
* @param string $tableTitle
* @param bool $horizontalDisplay
@christoferd
christoferd / gist:5679502
Created May 30, 2013 17:10
Bootstrap: brow
<div class="row">
<div class="span4">...</div>
<div class="span4 offset4">...</div>
</div>