[英]how to remove curly braces in php
我有一个变量$ uuid = {“ uuid”:“ 28fb72ed-0e97-4e78-9404-b676289b33ee ”};
执行后我得到的
我只需要提取28fb72ed-0e97-4e78-9404-b676289b33ee
你如何在PHP中做任何想法
我在这里包含一些代码我正在使用crcodoc查看器,并且现在已经使用crocodoc api生成了uuid来检查我分别需要uuid的状态...它传递了整个变量,我必须拆分并单独获取uuid
$ch = curl_init();
@curl_setopt($ch, CURLOPT_HEADER, 0);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
@curl_setopt($ch, CURLOPT_POST, 1);
@curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
@curl_setopt($ch, CURLOPT_URL, $frameUrl);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$uuids = curl_exec($ch);
echo $uuids;
echo "\n\nchecking status of : ", $uuids;
$status =getStatus($uuids,$api_url,$myToken);
可能应该在这里使用regex或explode()或implode()函数
有人可以帮忙..
谢谢
2个解决方案。
使用JSON更容易:
$str = '{"uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee"}';
$obj = json_decode($str);
echo $obj->uuid;
OUTPUT:
28fb72ed-0e97-4e78-9404-b676289b33ee
正则表达式第二
$str = '{"uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee"}';
preg_match('/"uuid": "([^"]+?)"/', $str, $matches);
print_r($matches);
输出:
Array ( [0] => "uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee" [1] => 28fb72ed-0e97-4e78-9404-b676289b33ee )
$matches[1]
拥有您需要的价值。
试试看
echo $uuid->uuid;
可能会给你
此代码将解决您的错误:
preg_replace('/{}/', '', $uuids);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.