PHP - Correct way to add space between numbers?
问题 Probably a simple problem if you know the answer. What I have Numbers with no spaces. $str = 10000; $str2 = 100000; What I want Convert above to below... $str = '10 000'; $str2 = '100 000'; Own thoughts I thought of some strpos, regexp, str_replace but is it really the way to solve this? I will accept the most correct, short code answer with no lack of speed. 回答1: Use number_format function. With space for thoudsandsSparator as below. number_format($number, 0, '.', ' ') Codepad Demo. 回答2: