在调用HTTP API时,我得到一个整数字符串作为结果。 var_dump与下面的
相同string '249139110' (length=12)
但是这个字符串有一些不可见的字符。我尝试了下面的代码
foreach (count_chars($id, 1) as $i => $val) {
echo "<br>There were $val instance(s) of \"" , chr($i) , "\" in the string." . ord($i) . " : " .gettype($i) ;
}
以及我喜欢的结果
There were 1 instance(s) of "0" in the string.52 : integer
There were 3 instance(s) of "1" in the string.52 : integer
There were 1 instance(s) of "2" in the string.53 : integer
There were 1 instance(s) of "3" in the string.53 : integer
There were 1 instance(s) of "4" in the string.53 : integer
There were 2 instance(s) of "9" in the string.53 : integer
There were 1 instance(s) of "�" in the string.49 : integer
There were 1 instance(s) of "�" in the string.49 : integer
There were 1 instance(s) of "�" in the string.50 : integer
请帮我删除这些�字符。提前谢谢。
答案 0 :(得分:1)
func fill(buffer: UnsafeMutableRawPointer!) -> Int {
buffer[33] = 0
}
和FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH
将执行此操作尝试下面的代码
FILTER_UNSAFE_RAW
输出将是:
$unsafe='There were 1 instance(s) of "�" in the string.49 : integer';
$string = filter_var($unsafe, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
echo $string;
有关详细信息,请参阅:String sanitization through filter_var