PHP 从 mysql 回显十六进制

标签 php mysql hex uuid

在 PHP 中,我想将 UUID 作为文本从 mysql 数据库打印

$con = mysql_connect("localhost","user","pass");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db('advancedban', $con);

$query="SELECT * FROM bm_name_bans";                    
$results = mysql_query($query);
while ($row = mysql_fetch_array($results)) {
    echo $row['actor_id'];
}

行 actor_is 的类型为二进制(16),在网站上我将得到 *?|?O2a?GCtq??I 你能帮我获取输出082a3f7c3f4f32613f474374713f3f49吗?

最佳答案

您需要将二进制字符串转换为十六进制字符串。您可以组合使用 dechexord PHP 函数,如下所示:

$row['actor_id'] = '*?|?O2a?GCtq??I';

for ($i = 0; $i < strlen($row['actor_id']); $i++) {
    $currentChar = $row['actor_id'][$i]; // you can access string characters like it is an array
    echo dechex(ord($currentChar));
}

请注意,strlen 是二进制安全的,可以在此处使用。

关于PHP 从 mysql 回显十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41881611/

相关文章:

PHP匹配正则表达式中的多个完整单词

php - 更改不同页面的标题 Logo

php - WooCommerce - 添加到购物车没有变体 ID

单独的数据库类中的 MySQL 连接池 - 如何?

html - 使用@Page.Title 时不会出现注册标记!

php - 使用 SplFileObject 转换 CR 换行符

javascript - 是否可以在没有 API 的情况下将数据从一个网站导出到另一个网站?

mysql - 数据库设计——哪一种更好?

c++ - 错误 C2064 : term does not evaluate to a function taking 3 arguments

java - 十六进制字符串到日期时间格式