phpstr-replacezero-width-space

PHP fix zero-width-space inside string variable


I have zipcodes being outputted, coming from user inputted values. Looks like it is outputting zero-width-space \u200b sometimes at the beginning of the strings.

What is the best way to replace these from within php before echoing the variable?


Solution

  • I use this function to trim unicode spaces - this should work in your case too.

    function trimUnicode($str) {
        return preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str);
    }