duanjiu1894 2014-11-07 04:24
浏览 124
已采纳

在PHP中将特定字符串123456789打印为特定格式12xxxxx89

I want to print a string in specific format like :

<?php

$var  = "123456789";

echo $var; //expected output 12xxxxx89;
?>

Want to show first two and last two characters from string and show others in x format.How can i do that ?

  • 写回答

5条回答 默认 最新

  • duanchongchu5177 2014-11-07 04:30
    关注

    Easy

    echo substr_replace($var, str_repeat('x', max(strlen($var) - 4, 0)), 2, -2);
    

    This should handle strings at or below 4 characters in length too.

    Demo ~ <kbd>eval.in</kbd>

    Links to functions:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?