Php filters out unrecognized question mark characters in a file. when a txt file is opened, the question mark salisbury & nbsp; rd & nbsp; is displayed ;? Open & nbsp ;? The requested & nbsp; CONTRAC page also displays a question mark, which means that the characters are not recognized and you want to filter out these unrecognized characters. Failed to use several methods. $ str & nbsp; file_get_contents (example_te php filters out unrecognized question mark characters.
There is a file. the question mark is displayed after the txt file is opened.
Salisbury rd? Open? Requested CONTRAC
The question mark is displayed on the web page, which indicates that the question mark is not recognized.
I want to filter out these unrecognized characters.
I tried several methods, but none of them worked.
$str = file_get_contents('example_text.txt');
echo $str;
------ Solution --------------------
Try this method.
Function filter_utf8_char ($ ostr ){
Preg_match_all ('/[\ x {FF00}-\ x {FFEF}
------ Solution --------------------
\ X {0000}-\ x {00ff}
------ Solution --------------------
\ X {4e00}-\ x {9fff}] +/U', $ ostr, $ matches );
$ Str = join ('', $ matches [0]);
If ($ str = '') {// special characters must be processed individually.
$ Returnstr = '';
$ I = 0;
$ Str_length = strlen ($ ostr );
While ($ I <= $ str_length ){
$ Temp_str = substr ($ ostr, $ I, 1 );
$ Ascnum = Ord ($ temp_str );
If ($ ascnum> = 224 ){
$ Returnstr = $ returnstr. substr ($ ostr, $ I, 3 );
$ I = $ I + 3;
} Elseif ($ ascnum >=192 ){
$ Returnstr = $ returnstr. substr ($ ostr, $ I, 2 );
$ I = $ I + 2;
} Elseif ($ ascnum >=65 & $ ascnum <= 90 ){
$ Returnstr = $ returnstr. substr ($ ostr, $ I, 1 );
$ I = $ I + 1;
} Elseif ($ ascnum >=128 & $ ascnum <= 191) {// special character
$ I = $ I + 1;
} Else {
$ Returnstr = $ returnstr. substr ($ ostr, $ I, 1 );
$ I = $ I + 1;
}
}
$ Str = $ returnstr;
Preg_match_all ('/[\ x {FF00}-\ x {FFEF}
------ Solution --------------------
\ X {0000}-\ x {00ff}
------ Solution --------------------
\ X {4e00}-\ x {9fff}] +/U', $ str, $ matches );
$ Str = join ('', $ matches [0]);
}
Return $ str;
}