-
-
Save ahmadazimi/b1f1b8f626d73728f7aa to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* http://stackoverflow.com/questions/11305797/remove-zero-width-space-characters-from-a-javascript-string | |
* U+200B zero width space | |
* U+200C zero width non-joiner Unicode code point | |
* U+200D zero width joiner Unicode code point | |
* U+FEFF zero width no-break space Unicode code point | |
*/ | |
$text = preg_replace( '/[\x{200B}-\x{200D}]/u', '', $text ); |
Awesome! How useful a single line of code has been. Thank you, it was what I needed!
Does not removes U+FEFF, if you use exact range shown in sample code.
You need to include it explicitly, out of character class.
$text = preg_replace( '/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $text );
Using @firestorm23 solution along with the gist worked for me. You can test it out by selecting the text here -> and running it through the preg_replace using firestorm23's solution
https://r12a.github.io/uniview/?charlist=*%2F%20%EF%BB%BF%40#title
$text = '*/ @';
$text = preg_replace('/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $text);
Github will probably strip the zero-width character in this comment in the $text
variable, just copy the text from link above
Does not removes U+FEFF, if you use exact range shown in sample code.
You need to include it explicitly, out of character class.
$text = preg_replace( '/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $text );
❤
Thank you That works
$text = preg_replace( '/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $text );
Thanks a lot, this was really helpful :)
THANK YOU!!!! I'm late to the party, but this really helped me out today.
thanks!