2

我有一个变量 $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()函数

有人可以帮忙吗..

谢谢

4

3 回答 3

5

2 解决方案。

使用 JSON 更容易:

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

输出:

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]有你需要的价值。

于 2013-05-24T12:52:57.013 回答
0

尝试

 echo $uuid->uuid;

愿它能给你

于 2013-05-24T12:25:54.933 回答
-1

此代码将解决您的错误:

preg_replace('/{}/', '', $uuids);
于 2013-05-24T12:39:22.777 回答