$str = preg_replace_callback( "#\\\u([0-9a-f]{4})#i", function($matchs) { return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1])); },
I searched the relevant information, understand a probable, but the essence of the part still do not understand.
1) The first parameter of the Preg_replace_callback () function should be a regular expression that matches the relevant character. But, among the two ' # ' and the last I I don't quite understand, for what?
2) The second parameter is a closure of the parameter $matchs is the system specified? Or just give me the name of a parameter? such as function ($a), and this place can only be a closure, can be rewritten with functions?
3) about this $matchs, after I test the output, it is a number of groups. Matchs[0] is u8fd8,matchs[1] is 8fd8. How did this happen? Using the previous regular expression I can only match to the results of matchs[0], minus u work and re-use matchs[1] to retain the result of removing u who did it? Is it the ' # ' after I?
Array( [0] => \u8fd8 [1] => 8fd8)
4) ' Iconv (' ucs-2be ', ' UTF-8 ', pack (' H4 ', $matchs [1])); After output, the return value of the Iconv () function is also how the Iconv () function is assembled inside? What is the role of H4 in the internal pack function? How to add to the front of the 8fd8.
Novice problem more Please the great gods, generous enlighten. Appreciate!
Reply content:
$str = preg_replace_callback( "#\\\u([0-9a-f]{4})#i", function($matchs) { return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1])); },
I searched the relevant information, understand a probable, but the essence of the part still do not understand.
1) The first parameter of the Preg_replace_callback () function should be a regular expression that matches the relevant character. But, among the two ' # ' and the last I I don't quite understand, for what?
2) The second parameter is a closure of the parameter $matchs is the system specified? Or just give me the name of a parameter? such as function ($a), and this place can only be a closure, can be rewritten with functions?
3) about this $matchs, after I test the output, it is a number of groups. Matchs[0] is u8fd8,matchs[1] is 8fd8. How did this happen? Using the previous regular expression I can only match to the results of matchs[0], minus u work and re-use matchs[1] to retain the result of removing u who did it? Is it the ' # ' after I?
Array( [0] => \u8fd8 [1] => 8fd8)
4) ' Iconv (' ucs-2be ', ' UTF-8 ', pack (' H4 ', $matchs [1])); After output, the return value of the Iconv () function is also how the Iconv () function is assembled inside? What is the role of H4 in the internal pack function? How to add to the front of the 8fd8.
Novice problem more Please the great gods, generous enlighten. Appreciate!
1 I regular wildcard meaning is case insensitive
2 $match variable name can be written casually. This is generally used
Preg_replace_callback ("/Expression/wildcard character", Array ($this, "a"), $string);
function A ($m) {
}
3 You didn't give the matching string an answer.
# can be replaced with any special symbol, as long as the uncommon on the line, you use "~", "/", "#" are the same, I means case-insensitive
Write casually, not necessarily $match
Iconv is a coded conversion function
The function of the above code is only used to convert strings of ucs-2be character format into Chinese characters.
Http://bbs.csdn.net/topics/39 ...