Skip to content

Instantly share code, notes, and snippets.

View wernerhp's full-sized avatar

Werner Pieterson wernerhp

View GitHub Profile
@wernerhp
wernerhp / nsprintf.php
Created June 1, 2015 09:24
Formats a string using an associative array.
/**
* Formats a string using an associative array.
* Example:
* echo nsprintf(":name :surname is :age", array('name' => 'John', 'age' => '29', 'surname' => 'Doe'));
*
* @param string $format A formatted string with named template fields
* @param array $args An associative array of values to place in the formatted string.
* @return string A formatted string
*/
function nsprintf($format, $args)