abdfahim Posted June 28, 2010 Share Posted June 28, 2010 Hi All, If I have in a string and I use html_entity_decode, it replaces with a white space which does not remove by str_replace(" ","",$string) So, what is the procedure to remove those space without using htmlentities() function? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/206091-html_entity_decode-and-nbsp/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2010 Share Posted June 28, 2010 Did you read the documentation for html_entity_decode(). It tells you what a is converted to - Notes Note: You might wonder why trim(html_entity_decode(' ')); doesn't reduce the string to an empty string, that's because the ' ' entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset. Quote Link to comment https://forums.phpfreaks.com/topic/206091-html_entity_decode-and-nbsp/#findComment-1078343 Share on other sites More sharing options...
Psycho Posted June 28, 2010 Share Posted June 28, 2010 EDIT PFMaBiSmAd already answered this. But, I'll post this nonetheless since I provided a code solution Well, a non-breaking space (i.e. ) is a different character than a breaking-space. The typical space character that allows line breaking is ASCII code 32, wherease the converted to a single character space is ASCII character 160. So you could either echo a non-breaking space character to the page and copy/paste that into your str_replace, or use the character code equivalent. str_replace(chr(160), "", $string) Quote Link to comment https://forums.phpfreaks.com/topic/206091-html_entity_decode-and-nbsp/#findComment-1078348 Share on other sites More sharing options...
abdfahim Posted June 29, 2010 Author Share Posted June 29, 2010 I am sorry to late reply, my internet connection was down last night .. Did you read the documentation for html_entity_decode(). It tells you what a is converted to - Notes Note: You might wonder why trim(html_entity_decode(' ')); doesn't reduce the string to an empty string, that's because the ' ' entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset. I did read that line before posting here but i didn't understand the significance. I though that note was applicable for trim function, not str_replace function. So, I was wondering whether there is any solution to remove once I use html_entity_decode, unless I go back using htmlentities(). EDIT PFMaBiSmAd already answered this. But, I'll post this nonetheless since I provided a code solution Well, a non-breaking space (i.e. ) is a different character than a breaking-space. The typical space character that allows line breaking is ASCII code 32, wherease the converted to a single character space is ASCII character 160. So you could either echo a non-breaking space character to the page and copy/paste that into your str_replace, or use the character code equivalent. str_replace(chr(160), "", $string) Thanks very much, i was looking exactly for this. Thanks everybody. Quote Link to comment https://forums.phpfreaks.com/topic/206091-html_entity_decode-and-nbsp/#findComment-1078531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.