Jump to content

html_entity_decode and nbsp;


abdfahim

Recommended Posts

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.

 

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)

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.