Php format numbers in a string with regexp

后端 未结 2 868
情话喂你
情话喂你 2021-01-21 18:25

I need help with writing a regular expression in PHP. I am not friend enough to get it right. I need to find all integers in a string and format them as follows:



        
2条回答
  •  长发绾君心
    2021-01-21 19:02

    From your examples looks like you are multiplying the number with 1000 and prefixing them with 0's to make a total of 6 digits. If that is true you can just do:

    sprintf("%06d",$n*1000);
    

提交回复
热议问题