PHP添加破折号进行解码
如果我现在有uuid,它会像这个42f704ab4ae141c78c185558f9447748一样出现,但是有可能让它在这个42f704ab-4ae1-41c7-8c18-5558f9447748中串起来,所以在某些地方有破折号吗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
<?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;