I have an associative array with such an element (part of 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] =>
)
)
)
)
Iam using json_encode($t['przeplywy']); to save it into MySQL DB as longtext utf8_general_ci. In the DB I can see it as :
[{"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",""]]}]
when I try to decode it I get null and http://json.parser.online.fr/ claims that is because "bad control character in string literal" what is wrong?
从查询结果中删除控制字符就可以了...
preg_replace('/[\x00-\x1F\x7F]/', '',$row['przeplywy'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.