开发者

PHP: Simplest way to add a string to a position in a string?

开发者 https://www.devze.com 2023-02-04 20:23 出处:网络
I know i could write a custom function that does just this, but it feels like this is such a function that should already exist (built in).

I know i could write a custom function that does just this, but it feels like this is such a function that should already exist (built in).

So,开发者_运维问答 i simply just want to add spaces to make it easier to read:

1200 would become: 1 200 10000 would become: 10 000 150000 would become: 150 000 etc...

Is there a function to just "pop" in a string/character into another string at a specified position?


Are you just formatting numbers? there's number_format() which will accept any type of seperator:

$formatted = number_format(1200, 0, '.', ' '); // "1 200"
                                 1   2    3
1. # of decimal places
2. decimal place character (not inserted, since we've specified 0 decimals)
3. thousands separator (space, in this case)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号