Php filters out unrecognized question mark characters

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.