Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP添加破折号进行解码_Php_Json_String - Fatal编程技术网

PHP添加破折号进行解码

PHP添加破折号进行解码,php,json,string,Php,Json,String,如果我现在有uuid,它会像这个42f704ab4ae141c78c185558f9447748一样出现,但是有可能让它在这个42f704ab-4ae1-41c7-8c18-5558f9447748中串起来,所以在某些地方有破折号吗 <?php $playername = 'Vanture'; $url = "https://api.mojang.com/users/profiles/minecraft/" . urlencode($playername); $result = file

如果我现在有uuid,它会像这个42f704ab4ae141c78c185558f9447748一样出现,但是有可能让它在这个42f704ab-4ae1-41c7-8c18-5558f9447748中串起来,所以在某些地方有破折号吗

<?php 
$playername = 'Vanture';
$url = "https://api.mojang.com/users/profiles/minecraft/" . urlencode($playername);
$result = file_get_contents($url);
$json = json_decode($result);
if ($json == NULL) {
    echo("NULL returned - probably invalid playername");
} else {
    $UUID = $json->id;
    echo "$UUID $playername";
}
?>

还有另一种方法:

$input = "42f704ab4ae141c78c185558f9447748";
$uuid = preg_replace("/(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/i", "$1-$2-$3-$4-$5", $input);
echo $uuid;

不需要解码。它只是一个字符串,所以使用字符串工具来操作它。
$input = "42f704ab4ae141c78c185558f9447748";
$uuid = preg_replace("/(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/i", "$1-$2-$3-$4-$5", $input);
echo $uuid;