Puddinq.com sharing knowledge

Regex cheatsheet

Regex cheatsheet

Links

negative lookbehind

Find space not precede bij \

(?<!\\)\s

Dynamically replace countries with code

function country($country) {
	$countries = array(
            '(etherlands|ederland)' => 'NL',
            '(weden)' => 'SE',
	    '(inland)' => 'FI'
	);
	
	foreach ($countries as $key => $coutryCode) {
		if (preg_match("/{$key}/i", $country)) {
        	$code= $coutryCode;
				break;
			}
		}
	}

return $code;
}