質問

I am having one variable $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

how do you do it in php any ideas

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

    $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

can someone help ..

thanks

役に立ちましたか?

解決

2 solutions.

Easier with JSON:

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

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.

他のヒント

Try with

 echo $uuid->uuid;

may it will give you

This code will solve your bug:

preg_replace('/{}/', '', $uuids);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top