When the white space became a beast

HEAVY WORDS
HEAVY WORDS

The legend of the white space

Every now and then, on the World Wide Web, someone meets the “white space” or for us: "the beast".

When we meet the beast, it drives us crazy, we get scared, we can’t understand what our eyes see, we cannot explain what’s going on, we wonder if something affected our perception. A supernatural phenomenon is in front of our eyes and overwhelms us.

We also got into it twice! Once on a website and once even inside of a Excel sheet! It’s unbelievable the places where this creature summons and the way it got there is an even bigger mystery!

The brave who went after it

Some give up, run and hide from it. Or just accept it without questioning its existence. But others, the brave ones, start on a journey through the darkness and don’t give up until they know the truth.

This is what someone who has been there and survived confessed (with shaking hands):

To the people in the future like myself that had to debug this from a high level all the way down to the character codes, I salute you.

crclayton - Sep 1 '16 at 21:22 - stackoverflow.com

We've also been there and we returned with the truth ready to share it with you.

How the creature looks and where does it come from

The strange space is actually the   entity (Wikipedia), pretty well known by HTML coders but in this case it is not represented/encoded in HTML.

So basically most of us knew the creature, but we didn’t know it could exist in another shape and dimension.

Wikipedia explains the different representations of the beast:

And also how the creature is born and mutates:


The tools and techniques to find it and get rid of it

For the even braver who want to go after it and make it disappear we’ve got some tools and techniques to help locating it and still come back alive from the journey.

Web tool that looks for it in the code of a webpage:

Here’s a tool with a web interface where you can enter a URL and it searches the contents of that page in order to find the beast:

http://tools.heavydots.com/nbsp-space-char-detect/

Manual cleanup technique:

But if you find yourself in the dark code dimension and cannot use the web, and you have to get very close to the beast in order to kill it, here is a way to exorcise your demonized code:

Only for those who are skilled with PHP spells, run a search of chr(194).chr(160) and replace it with an ordinary space. This will extract the demon out of it and will restore back its clean white space soul.

Take this scroll with you, it contains the spell you will need when you face the beast

// Define the white beast
$white_beast=chr(194).chr(160);

// Count how many of them are living in your text
$count=substr_count($string, $white_beast);
print_r($count);

// Replace it with a normal space
$string=str_replace($white_beast, ' ', $string);

THE END of the story

So dear reader of this legend, if you never faced the beast, beware!

But if you have also had to deal with it, please share with us your story in the comments section! 

Need help with your project?