php - 在 jpeg 数字之间插入空格

标签 php css wordpress post

使用下一个代码,我可以用图像更改号码(我不想让谷歌知道这个电话号码)。是否可以每 3 个数字/图像插入空格?

比如手机是111222333,我要在前面显示111 222 333。

<?php global $wp_query; 
$postid = $wp_query->post->ID; 
$i=intval(get_post_meta($postid, 'telefono_2', true));
$s='';
while($i>0)
    {
    $digit=$i % 10;
    $i=(int)($i/10);
    $s="<img style='vertical-align:middle;' src='http://localhost/buscatuescort/wp-content/themes/Avada/images/$digit.png' width='12' height='18' />$s";
    }
echo $s ?>

最佳答案

您只需添加某种计数器 并在循环的每 3 个迭代步骤中向字符串添加一个空格。也许是这样的:

$spacer=0;
while($i>0)
    {
    $digit=$i % 10;
    $i=(int)($i/10);
    $s="<img style='vertical-align:middle;' src='http://localhost/buscatuescort/wp-content/themes/Avada/images/$digit.png' width='12' height='18' />"
       . ($spacer++ % 3 == 0 ? "&nbsp;" : "") . $s;
    }

备注:

当您从最后一位数字向后迭代时,如下所示:

11122233

会像这样打印出来:

11 122 233

但是如果你想得到这样的东西:

111 222 33

您将不得不编写一个略有不同的循环。也许是这样的:

$i = "$i";
$length = strlen($i);
for($key = 0; $key < $length; $key++){
    $s .= ($key % 3 == 0 ? "&nbsp;" : "")
          . "<img style='vertical-align:middle;' src='http://localhost/buscatuescort/wp-content/themes/Avada/images/$i[$key].png' width='12' height='18' />";
}

(我将 $i 更改为字符串以循环遍历数字,就像这样 $i[$key])

关于php - 在 jpeg 数字之间插入空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19625779/

相关文章:

php - Yii 验证规则 - 唯一

PHP/亚马逊 S3 : Query string authentication sometimes fails

css - 选择标签上的背景颜色会破坏 Firefox UI

WordPress 上的 CSS

javascript - 在 Wordpress 中保存 Widget 后 TinyMCE 消失

php - array_merge() : Argument #1 is not an array in laravel 5. 5

php - 在单个查询php mysql中更新多行

javascript - 随机.addClass到多个div而不重复

html - IOS8 : whole page scrolls down when input in fixed footer gets focus

php - 使用 SQL 查询获取所有 WooCommerce 客户支付的订单