我正在使用的数据库具有存储为文本值的字符串数组,例如:
“ [\”收音机\ / CD \“,\”电视\“,\”体重计\“]”
(不知道为什么这样存储)
无论如何,我需要将其转换为常规数组,例如:
数组([0] =>重量计[1] =>电视[2] =>收音机/ CD)
由于其存储方式,我无法进行常规的php爆炸,例如:
<?php
$input = '"[\"Radio\\\/CD\",\"TV\",\"Weight Gauge\"]"';
echo "Input string:<br>" . $input . "<br><br>";
$output = explode(",", stripslashes($input));
print_r($output);
?>
结果数组(不是我想要的):
数组([0] =>“ [”收音机/ CD“ [1] =>” TV“ [2] =>”体重计“]”)
谢谢
看起来是双重JSON编码。
采用 json_decode
$input = '"[\"Radio\\\/CD\",\"TV\",\"Weight Gauge\"]"';
$output = json_decode(json_decode($input));
print_r($output);
输出:
Array
(
[0] => Radio/CD
[1] => TV
[2] => Weight Gauge
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句