本文介绍了替换最后x个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的PHP变量:

I have a PHP variable that looks a bit like this:

$id = "01922312";

我需要用另一个字符替换最后两个或三个数字.我该怎么做呢?

I need to replace the last two or three numbers with another character. How can I go about doing this?

编辑很抱歉,基本上我上面有变量,在完成处理后,我希望它看起来像这样:

EDIT Sorry for the confusion, basically I have the variable above, and after I'm done processing it I'd like for it to look something like this:

$new = "01922xxx";

推荐答案

尝试一下:

$new = substr($id, 0, -3) . 'xxx';

结果:

01922xxx

这篇关于替换最后x个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:44