Posts Learn Components Snippets Categories Tags Tools About

How to Trim   with PHP

Learn how to trim   with PHP the easy way using the trim function and also specifying the special character

Created on Nov 19, 2021


In this short snippet you will learn how to trim   using trim() function. To do that you can simply use the trim and the pass in the string to trim as the 1st parameter and 2nd parameter the special character to trim. In this case, it would be "chr(0xC2).chr(0xA0)". For the code implementation do refer to the code example below.

$key = ' '; // imagine the content of this $key is &nbsp;

$newKey = trim($key, chr(0xC2).chr(0xA0));

if ($newKey === '') {
    echo 'it\'s empty';

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Trim &nbsp; with PHP