utf 8 - PHP remove special characters to make sure a string is utf-8 encoded -


i @ lost of how remove special characters string make sure chars supported uft-8 + french chars included. below base64 string has special chars , sanitizing function has failed remove them , causing text not print when using fpdf cells etc. if decode string @ https://www.base64decode.org/ see special chars.

// sanitizing function static function remove_none_word_chars($string) {         return preg_replace('/[^a-za-z0-9`_.,;@#%~\’\'\"+*\?\^\[\]\$\(\)\{\}\=!\<\>\|\-:\s\/\\sàâçéèêëîïôûùüÿñæœ]/ui', '', $string);     }  74knifn1cgvydmlzzxigbgugdhjhdmfpbcbkzsbs4oczzw5zzw1ibgugzhugcgvyc29ubmvsigrlihbyb2r1y3rpb24sigrligzigjllbnryzxrpzw4gzxqgzgugbgegbwfpbnrlbmfuy2ugc3vyigxlihf1yxj0igrlig51axqgzw4gdgvuyw50ignvbxb0zsbkzsbsysbjb252zw50aw9uignvbgxly3rpdmu7cu+cpybbc3n1cmvyihvuzsbib25uzsbnzxn0aw9uigrligzigjllbnnlbwjszsbkzxmgb3ddqxjhdglvbnmgzgugbokamxvzaw5lowrvgqcgugxhbmlmawvyigrlcybvcmopcmf0aw9ucyblbibmb25jdglvbibkzxmgym9ucybkzsbjb21tyw5kztsk74kniefwcg9ydgvyigxlcybtb2rpzmljyxrpb25zigv4awfdqwvzigxvcnmgzgvzigrpzmbdqxjlbnrzigf1zgl0cyaor2vuzxjhbcbeew5hbwljcywgsvnpotawmswgt0htqvmxodawmswgzxrjlik7cu+cpybszw5kcmugy29tchrligr1ihn1axzpigrlcybvcmopcmf0aw9ucyddocbjagfxdwugzglyzwn0zxvyigrligtdqxbhcnrlbwvudcbsb3jzigr1ignoyw5nzw1lbnqgzgugcxvhcnq7cu+cpybwb2lyigf1ihn1axzpigrlcybidwrnzxrzigv0igvuigfzc3vyzxigbgugcmvzcgvjdc4= 

update answers above function indeed work there conditional statement forgot change elsewhere thats way :( embarrassing.

to remove non-printing characters, can use regular expression.

$data= preg_replace('/[^\x0a\x20-\x7e\xc0-\xd6\xd8-\xf6\xf8-\xff]/','',$data);  // or preserve extended characters, use below expression. // mind many of these may still non-printing. $data= preg_replace('/(?!\n)[[:cntrl:]]+/','',$data); 

this answer previous question of mine remove non-printing characters string destined error_log.

what remove characters not in provided list, or (in second example) control characters. lists:

\x0a = [newline] \x20-\x7e = [space] ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ b c d e f g h j k l m n o p q r s t u v w x y z [ \ ] ^ _ ` b c d e f g h j k l m n o p q r s t u v w x y z { | } ~ \xc0-\xd6 = À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö \xd8-\xf6 = Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö \xf8-\xff = ø ù ú û ü ý þ ÿ 

as encoding utf-8, shouldn't of problem, there functions available, such utf8-encode, may help. believe have call on string prior removing non-printing characters. please note, however, if string not int correct format, or in utf-8, may make string unreadable.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -