PHP filters out unrecognized question mark characters
There is a file, txt open after a few places to display question mark
Salisbury Rd open? requested Contrac
A question mark is also displayed on the page, meaning it is not recognized
Want to filter out the characters that are not recognized.
Tried a few ways.
$str = file_get_contents (' example_text.txt ');
Echo $str;
Share to: more
\X{0000}-\X{00FF} Try this method to filter down.
function Filter_utf8_char ($OSTR) {
Preg_match_all ('/[\x{ff00}-\x{ffef}\x{0000}-\x{00ff}\x{4e00}-\x{9fff}]+/u ', $ostr, $matches);
$str = Join ("', $matches [0]);
if ($str = = ") {//contains special characters that need to be handled 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 characters
$i = $i + 1;
}else{
$returnstr = $returnstr. substr ($ostr, $i, 1);
$i = $i + 1;
}
}
$str = $returnstr;
Preg_match_all ('/[\x{ff00}-\x{ffef}\x{4e00}-\x{9fff}]+/u ', $str, $matches);
$str = Join ("', $matches [0]);
}
return $str;
}