PHP添加破折号进行解码 [英] PHP Add dash to decode

查看:180
本文介绍了PHP添加破折号进行解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我现在有uuid,它将像这样的42f704ab4ae141c78c185558f9447748出来,但是有可能让它串入此42f704ab-4ae1-41c7-8c18-5558f9447748中,以便在某些地方带有破折号

If i have the uuid now it will come out like this 42f704ab4ae141c78c185558f9447748 But is it possible to let it string in this 42f704ab-4ae1-41c7-8c18-5558f9447748 so with dashes on the certain places

<?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";
}
?>

推荐答案

<?php 

//$UUID = 42f704ab-4ae1-41c7-8c18-5558f944774
$UUID = "42f704ab4ae141c78c185558f9447748";


$UUID = substr($UUID, 0, 8) . '-' . substr($UUID, 8, 4) . '-' . substr($UUID, 12, 4) . '-' . substr($UUID, 16, 4)  . '-' . substr($UUID, 20);
echo $UUID;

这篇关于PHP添加破折号进行解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆