Markus Hedlund

Developer / Photographer

Contact / GitHub / Instagram

Trim unicode/UTF-8 whitespace in PHP

preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string);

This will effectively remove any weird whitespace characters, control characters and even those pesky Apple logos.

Have a look at the page below for more information on the Unicode characters and regular expressions.

nadeausoftware.com

2010-11-12