Skip to content

Instantly share code, notes, and snippets.

@JonnyNineToes
JonnyNineToes / PHP Title Case
Last active June 28, 2023 07:48
PHP Title Case function
function titleCase($string) {
//reference http://grammar.about.com/od/tz/g/Title-Case.htm
// The below array contains the most commonly non-capitalized words in title casing - I'm not so sure about the commented ones that follow it...
$minorWords = array('a','an','and','as','at','but','by','for','in','nor','of','on','or','per','the','to','with'); // but, is, if, then, else, when, from, off, out, over, into,
// take the input string, trim whitespace from the ends, single out all repeating whitespace
$string = preg_replace('/[ ]+/', ' ', trim($string));
// explode string into array of words
$pieces = explode(' ', $string);
// for each element in array...
for($p = 0; $p <= (count($pieces) - 1); $p++){
@cangelis
cangelis / command.class.php
Last active June 21, 2023 02:03
A simple Command Pattern implementation (Calculator example) on PHP
<?php
abstract class Command {
abstract public function unExecute ();
abstract public function Execute ();
}
class concreteCommand extends Command {
private $operator,$operand,$calculator;
public function __construct ($calculator,$operator,$operand) {
$this->operator = $operator;
$this->operand = $operand;
@aeurielesn
aeurielesn / util.php
Created July 31, 2011 03:47
Decode Unicode strings in PHP
<?php
#source: http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-char
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function unicode_decode($str) {
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}