<?php
$str = 'plstrim';
$spaces = [
// The horizontal space characters are:
"\u{0009}", // Horizontal tab (HT)
"\u{0020}", // Space
"\u{00A0}", // Non-break space
"\u{1680}", // Ogham space mark
"\u{180E}", // Mongolian vowel separator
"\u{2000}", // En quad
"\u{2001}", // Em quad
"\u{2002}", // En space
"\u{2003}", // Em space
"\u{2004}", // Three-per-em space
"\u{2005}", // Four-per-em space
"\u{2006}", // Six-per-em space
"\u{2007}", // Figure space
"\u{2008}", // Punctuation space
"\u{2009}", // Thin space
"\u{200A}", // Hair space
"\u{202F}", // Narrow no-break space
"\u{205F}", // Medium mathematical space
"\u{3000}", // Ideographic space
// The vertical space characters are:
"\u{000A}", // Linefeed (LF)
"\u{000B}", // Vertical tab (VT)
"\u{000C}", // Form feed (FF)
"\u{000D}", // Carriage return (CR)
"\u{0085}", // Next line (NEL)
"\u{2028}", // Line separator
"\u{2029}" // Paragraph separator
];
foreach($spaces as $s) {
$totrim = $str . $s . $s . $s;
$trimmed = preg_replace('~\s+$~us', '\1', $totrim); // right-trimming
$sname = str_pad(strtoupper(dechex(IntlChar::ord($s))), 4, '0', STR_PAD_LEFT);
var_dump([$sname, $totrim, $trimmed]);
}
preferences:
25.19 ms | 408 KiB | 5 Q