Last active
April 9, 2021 11:19
-
-
Save skrajewski/81b02879a8dfec79e12d to your computer and use it in GitHub Desktop.
Replace non-breaking spaces with normal spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Replace non-breaking spaces with normal spaces | |
* | |
* @param $str | |
* @return string | |
*/ | |
public function removeNbsp($str) | |
{ | |
$str = htmlentities($str); | |
$str = str_replace(" ", " ", $str); | |
$str = html_entity_decode($str); | |
return $str; | |
} |
$regular_spaces = str_replace("\xc2\xa0", ' ', $original_string);
This breaks Unicode characters..
This breaks Unicode characters..
@nirmit Why should this break unicode characters? Can you please elaborate on this why you think it does break them. Thank you!
(Looks like it is a upvoted and accepted answer here: https://stackoverflow.com/questions/40724543/how-to-replace-decoded-non-breakable-space-nbsp)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$regular_spaces = str_replace("\xc2\xa0", ' ', $original_string);