简体   繁体   English

如何在PHP中删除花括号

[英]how to remove curly braces in php

I am having one variable $uuid={"uuid": " 28fb72ed-0e97-4e78-9404-b676289b33ee "}; 我有一个变量$ uuid = {“ uuid”:“ 28fb72ed-0e97-4e78-9404-b676289b33ee ”};

which i am getting after execution 执行后我得到的

i need to extract 28fb72ed-0e97-4e78-9404-b676289b33ee just the number 我只需要提取28fb72ed-0e97-4e78-9404-b676289b33ee

how do you do it in php any ideas 你如何在PHP中做任何想法

i am including some code here i am using crcodoc viewer and i have generated the uuid using crocodoc api now to check the status i need the uuid seperatly ... it is passing the whole variable i have to split and get the uuid alone 我在这里包含一些代码我正在使用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);

probably regex or explode () or implode () function should be used here 可能应该在这里使用regex或explode()或implode()函数

can someone help .. 有人可以帮忙..

thanks 谢谢

2 solutions. 2个解决方案。

Easier with JSON: 使用JSON更容易:

$str = '{"uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee"}';
$obj  = json_decode($str);
echo $obj->uuid;

OUTPUT: OUTPUT:

28fb72ed-0e97-4e78-9404-b676289b33ee

Second with Regex 正则表达式第二

$str = '{"uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee"}';

preg_match('/"uuid": "([^"]+?)"/', $str, $matches);
print_r($matches);

Output: 输出:

Array ( [0] => "uuid": "28fb72ed-0e97-4e78-9404-b676289b33ee" [1] => 28fb72ed-0e97-4e78-9404-b676289b33ee )

$matches[1] has got value you need. $matches[1]拥有您需要的价值。

Try with 试试看

 echo $uuid->uuid;

may it will give you 可能会给你

此代码将解决您的错误:

preg_replace('/{}/', '', $uuids);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM