If
$text = ' MEANINGFUL THINGS GO HERE ';
How can I get
$cleanText = 'MEANINGFUL THINGS GO HERE';
I know the following will remove all the white spaces
$text=trim($text);
but how can incorporate actual escaped space into the trim as well?
Meaningful Things can contain [shortcodes], html tags, and also escaped characters. I need these to be preserved.
Any help would be appreciated. Thanks!
$text = ' MEANINGFUL THINGS GO HERE ';
$text = preg_replace( "#(^( |\s)+|( |\s)+$)#", "", $text );
var_dump( $text );
//string(25) "MEANINGFUL THINGS GO HERE"
additional tests
$text = ' S S ';
-->
string(24) "S S"
$text = ' ';
-->
string(0) ""
$text = ' &nbst; &nbst; ';
-->
string(18) "&nbst; &nbst;"
Also run an html_entity_decode on this, then trim:
$text=trim(html_entity_decode($text));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With