从 PHP 中的输出中去除大括号
Strip curly bracket from an output in PHP
我的 php 代码 <?php echo $art->capt; ?>
给出以下输出:
{"path":"location\/file.png"}
但是,我只想显示 location/file.png
作为输出并删除所有垃圾。
我应该如何进行?
那是 json。你需要解码它。
<?php
$str = $art->$capt; //'{"path":"location\/file.png"}';
$json = json_decode($str, true);
$path = $json['path'];
echo($path);
?>
其实就是JSON, you can use json_decode把它变成一个对象(或者数组,如果你在json_decode的第二个参数中传递true)。获取 HTML 输出。如果 HTML 尚未在变量中,请使用输出缓冲。
ob_start();
/*html is output here*/
$json = ob_get_contents();
$json = json_decode($json, true);
$path = $json['path'];
print_r($path);
//output should be location/file.png
我的 php 代码 <?php echo $art->capt; ?>
给出以下输出:
{"path":"location\/file.png"}
但是,我只想显示 location/file.png
作为输出并删除所有垃圾。
我应该如何进行?
那是 json。你需要解码它。
<?php
$str = $art->$capt; //'{"path":"location\/file.png"}';
$json = json_decode($str, true);
$path = $json['path'];
echo($path);
?>
其实就是JSON, you can use json_decode把它变成一个对象(或者数组,如果你在json_decode的第二个参数中传递true)。获取 HTML 输出。如果 HTML 尚未在变量中,请使用输出缓冲。
ob_start();
/*html is output here*/
$json = ob_get_contents();
$json = json_decode($json, true);
$path = $json['path'];
print_r($path);
//output should be location/file.png