[wp-trac] [WordPress Trac] #63804: Proposal of wp_trim(): JavaScript-compatible alternative for trim()
WordPress Trac
noreply at wordpress.org
Sat Aug 9 16:12:16 UTC 2025
#63804: Proposal of wp_trim(): JavaScript-compatible alternative for trim()
--------------------------+------------------------------
Reporter: takayukister | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by dmsnell):
Thanks @takayukister — there are clearly growing needs to harmonize code
between PHP and JavaScript. I wonder if it wouldn’t be clearer to think
about functions acknowledging just that. For instance, instead of
`wp_trim()`, which itself would introduce a third new set of semantics, to
write `js_trim()`, where we could always compare the behavior of that
function against `String.prototype.trim()`.
Note also that we have existing mechanisms to match the behavior in
`mb_trim()` by passing a second parameter, the trim list. There’s another
way to think about this proposal as providing that set of characters.
{{{#!php
<?php
$js_trimmables =
"\x09\x0A\x0B\x0C\x0D\x20\u{0085}\u{00A0}\u{1680}\u{2000}…\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{FEFF}";
// No ".." ranges in `mb_trim()`
echo mb_trim( $string, $js_trimmables );
function js_trim( $string ) {
global $js_trimmables;
return mb_trim( $string, $js_trimmables );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63804#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list