限制哈希码仅包含 2 位数字
我有这个 $img['hash']
这是一个长哈希码 32-64 位 a09806aa003033128f44d5fd4c56786b (作为示例) php中有没有办法只提取第一个两位数(a0)
<?php
$cdb = new PDO('mysql:dbname=xxx;host=localhost', 'xxx', 'xxx');
foreach ($cdb->query("SELECT * FROM images ORDER BY posted DESC LIMIT 9") AS $img)
{
echo '<a style="position: relative; display: block; height: 200px;" href="/booru/post/view/' . $img['id'] . '" target="_blank">
<img src="booru/timthumb.php?src=thumbs/' . $img['hash'] . '&h=125&w=125" style="border-style: none"/>
</a>
';
}
抱歉我应该添加一些更多信息我需要保留$img['hash']所以
像这样
<img src="booru/timthumb.php?src=thumbs/' . $img['hash'] . '/Here/&h=125&w=125" width="125px" style="border-style: none"/>
我需要将它添加到“/here” /“ 是
I have this $img['hash']
which is a long hash code 32-64 digits a09806aa003033128f44d5fd4c56786b (as an example)
Is there any way in php to pull only the 1st two digits (a0)
<?php
$cdb = new PDO('mysql:dbname=xxx;host=localhost', 'xxx', 'xxx');
foreach ($cdb->query("SELECT * FROM images ORDER BY posted DESC LIMIT 9") AS $img)
{
echo '<a style="position: relative; display: block; height: 200px;" href="/booru/post/view/' . $img['id'] . '" target="_blank">
<img src="booru/timthumb.php?src=thumbs/' . $img['hash'] . '&h=125&w=125" style="border-style: none"/>
</a>
';
}
Sorry I should of added some more info I need to keep the $img['hash'] also
So like this
<img src="booru/timthumb.php?src=thumbs/' . $img['hash'] . '/Here/&h=125&w=125" width="125px" style="border-style: none"/>
I need to add it where the "/here/" is
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
substr()
获取子字符串一个字符串,在这种情况下你的哈希值:You can use
substr()
to get a substring of a string, in this case your hash:尝试:
Try:
是的,使用 substr:
Yes, use substr:
您可以使用 php 的 substr 方法(http://php.net/manual/en/function.substr.php)并输出:
这将输出 $img['hash'] 的从索引 0 开始的前 2 位数字细绳。
You can use php's substr method (http://php.net/manual/en/function.substr.php) and output:
Which will output the first 2 digits, starting at index 0, of the $img['hash'] string.
在 PHP 中你可以使用 substr
http://php.net/manual/en/function.substr.php
应该能解决问题
In PHP you can use substr
http://php.net/manual/en/function.substr.php
should do the trick