dongtanzhu5417 2019-01-26 14:40 采纳率: 100%
浏览 61
已采纳

如何将变量从java转换为php?

I'm creating player panel for my friend in php, but I have problem with variable shown below. I must insert into variable in php, and send request to database. What is my problem? I can't convert java code, because I don't know how I can do this. It may be strange, but unfortunately it is.

I tried do this with amateur way, using; require 'mojang-api.class.php';

$uuid = MojangAPI::getUuid('jeb_');
echo 'UUID: <b>' . $uuid . '</b><br>';
echo substr($uuid, 0, 8); echo '-'; echo substr($uuid, 8, 12); echo '-'; substr($uuid, 13, 15); echo '-';

but, You and I know this - this way sucks.

I place the java code below.

Java:

uuid.substring(0, 8) + '-' + uuid.substring(8, 12) + '-' + uuid.substring(12, 16) + '-' + uuid.substring(16, 20) + '-' + uuid.substring(20)

If someone can help me with this problem, I'll be grateful.

  • 写回答

1条回答 默认 最新

  • dougan0529 2019-01-26 15:21
    关注

    Is this what you are looking for

    $uuid = MojangAPI::getUuid('jeb_');
    echo 'UUID: <b>' . $uuid . '</b><br>';
    echo substr($uuid, 0, 8).'-'.substr($uuid, 8, 4).'-'.substr($uuid, 13, 2);
    

    Instead of plus + in Java you use the dot . in PHP. Amazingly you used it in the line above?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部