PHP string convert RMB form number

Source: Internet
Author: User

PHP is a scripting language, but it's magical, you use the post a string of numbers to pass, with Var_dump () print out, you will find that the string number format is string.

Today, I'm going to do a function to put 12 digits, such as: 000000100000

Like the above to be divided into units of numbers, the average person looks very troublesome, so we have to deal with the display as follows


It's easier to look like this. How to deal with, I intended to use regular, but/d is to match the number of 0-9, I would like to write a new way of matching, repeated reflection, or with

The Simple Way

function Transamt ($value)

{

//convert string to array

$array = Str_split ($value);

Arrays are traversed by

foreach ($array as $key => $va)

{

if ($va!= 0)

{

$ start = $key;

Break

;

}

}

Splits the string group

$len = strlen ($value)-$start;

$substr = substr ($value, $start, $len);

To process the data, first get the length of the substring

$smallnum = substr ($substr, -2,2);

$bignum = substr ($substr, 0, $len-2);

Return $bignum. ". $smallnum;

}

This is done by converting the string into arrays and then manipulating the array.

This should be regarded as the idiom of PHP operation string.

The simplest way of programming: encountering problems, proposing solutions to problems, and summing up many problems, and getting common ground.

In general, the process-oriented function is transformed into an object-oriented class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.