Search code examples
phpmysqlpreg-replacespecial-characters

How to remove the special characters in PHP


I've tried most things people have offered, I am trying to remove the tringle with the ? in the pics below.

Example "²" is causing the issue below.

This is how it prints:

enter image description here

This is whats in the database:

Size: 190(L) x 190(W) (Single Door) x 216(H)cm, 6mm, 3.6m² (6'3" x 6'3"), 3 Sections Long
Packaging Size: 161(L) x 62(W) x 13(H)cm, 193(L) x 21(W) x 14(H)cm   
Total Weight GW: 48.1kg

Database is formatted to Uft8

This is the code I currently have to try and get rid of it:

function removeNonUtf8($data){

    //$data = preg_replace('/\x{00B0}/u'," degress", $data );
    return preg_replace('/[^A-Za-z0-9 @#%~\'\"\®\©_\-\,\+\&.\}\=\!\<\>\|\:\-\\\\\+\*\?\[\^\]\$\(\)\{Â]/','', $data);

    $data = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $data);
    return $data;
}

After this it changes it to a different symbol, still doesn't get rid of it though.

enter image description here But its still not working?

Any hints?


Solution

  • First, special characters are printed with the tringle with ? Because the browser do not support this font. If you want to print it, follow this guild :http://jkorpela.fi/html/characters.html. Or you can simply specify a font list for your browser like the following:

    font-family: DejaVu Sans, Symbola, Everson Mono, Dingbats, Segoe UI Symbol,
     Quivira, SunExt-A, FreeSerif, Universalia, unifont;

    But if you want to remove it, change your regex pattern because it now does not match the characters you expected. Such as /²|other special characters../