Show / filter non-standard characters in the code editor (U+00a0 nbsp or other unicode)

Hello everyone

When we develop, we have a toolbox and references full of snippets.
Sometimes, they are websites with copy and paste from everywhere…

Let’s take for example this piece of code coming from a known website:

Try to copy-paste at the source only (not this forum): https://phpsources.net/code/php/fichiers-repertoires/117_connaitre-l-extension-d-une-image-ou-d-1-fichier

<?php
    $file = 'filename.txt';

    echo str_replace('.','',strstr($file, '.'));
    echo substr(strrchr($file,'.'),1);
    echo pathinfo($file, PATHINFO_EXTENSION);
?>

When you run it, you get this message:

Don’t look for it. The code is clean. But the formatting of the text is not.

With Wappler’s editor, I still lost more than a day’s work on 20 lines of code.

If you copy and paste into a known editor, you will be able to see the special characters if the option is activated.

simple code

Knowing this, before executing a code that has been pasted, and to avoid tearing my hair out and wasting time on debugging, I use a search and replace.

Replace U+00a0 (nbsp) (or other unicode) characters with your code editor

Open this from the “Search menu” (Ctrl+F) activate Use Regular Expression (.*) and search for the unicode character with regex [\xa0] and replace by space.

after_search

Even if it doesn’t take much time, it would be wise to see, or better: filter out special characters. A non-breaking space has no interest in a code.

I hope this request is relevant.
See you soon

Community Page
Last updated: