从数据库读取时,字符串文字中的 PHP 错误控制字符


php bad control character in string literal, when reading from db

我有一个带有这样一个元素的关联数组(print_r($element)的一部分):

[przeplywy] => Array
    (
        [0] => Array
            (
                [probes] => Array
                    (
                        [0] => sonda-10
                    )
                [flow] => Array
                    (
                        [0] => Array
                            (
                                [0] => created
                                [1] => sip
                                [2] => sport
                                [3] => dip
                                [4] => dport
                                [5] => proto
                                [6] => sensor
                                [7] => os
                            )
                        [1] => Array
                            (
                                [0] => 2013-09-12 06:10:26
                                [1] => 192.168.0.1
                                [2] => 18560
                                [3] => 10.0.0.1
                                [4] => 1900
                                [5] => UDP
                                [6] => sonda-10
                                [7] => 
                            )
                        [2] => Array
                            (
                                [0] => 2013-09-12 09:31:08
                                [1] => 192.168.0.1
                                [2] => 13011
                                [3] => 10.0.0.1
                                [4] => 1900
                                [5] => UDP
                                [6] => sonda-10
                                [7] => 
                            )
                        [3] => Array
                            (
                                [0] => 2013-09-12 09:37:42
                                [1] => 192.168.0.1
                                [2] => 4813
                                [3] => 10.0.0.1
                                [4] => 1900
                                [5] => UDP
                                [6] => sonda-10
                                [7] => 
                            )
                        [4] => Array
                            (
                                [0] => 2013-09-12 11:24:41
                                [1] => 192.168.0.1
                                [2] => 50091
                                [3] => 10.0.0.1
                                [4] => 1900
                                [5] => UDP
                                [6] => sonda-10
                                [7] => 
                            )
                        [5] => Array
                            (
                                [0] => 2013-09-12 13:36:55
                                [1] => 192.168.0.1
                                [2] => 17064
                                [3] => 10.0.0.1
                                [4] => 1900
                                [5] => UDP
                                [6] => sonda-10
                                [7] => 
                            )
                    )
            )
    )

我正在使用json_encode($t['przeplywy'])将其作为长文本utf8_general_ci保存到MySQL DB中。在数据库中,我可以将其视为:

[{"probes":["sonda-10"],"flow":[["created","sip","sport","dip","dport","proto","sensor","os"],["2013-09-12 06:10:26","192.168.0.1","18560","10.0.0.1","1900","UDP","sonda-10",""],["2013-09-12 09:31:08","192.168.0.1","13011","10.0.0.1","1900","UDP","sonda-10",""],["2013-09-12 09:37:42","192.168.0.1","4813","10.0.0.1","1900","UDP","sonda-10",""],["2013-09-12 11:24:41","192.168.0.1","50091","10.0.0.1","1900","UDP","sonda-10",""],["2013-09-12 13:36:55","192.168.0.1","17064","10.0.0.1","1900","UDP","sonda-10",""]]}]

当我尝试解码它时,我得到 null 并 http://json.parser.online.fr/声明这是因为"字符串文字中的错误控制字符"有什么问题?

从查询结果中删除控制字符就可以了...

preg_replace('/['x00-'x1F'x7F]/', '',$row['przeplywy'])