The example in this article describes the method by which the PHP implementation splits a string at a specified distance. Share to everyone for your reference. Specifically as follows:
Adding a comma to every three characters of a string, such as converting the string 1234567890 to 1,234,567,890, is a common practice in the financial world
<?php
/**
* Every 3 characters, separated by commas
* @param string $str
* @return string/
function Splitstrwithcomma ($str)
{
$arr = array ();
$len = strlen ($STR);
for ($i = $len-1; $i >= 0;) {
$new _str = "";
for ($j = $i; $j > $i-3 && $j >= 0; $j-) {
$new _str. = $str [$j];
}
$arr [] = $new _str;
$i = $j;
}
$string = Implode (', ', $arr);
Flip the string yourself to implement
//$string = Strrev ($string);
for ($i = 0, $j = strlen ($string)-1; $i <= $j; $i + +, $j-) {
$tmp = $string [$i];
$string [$i] = $string [$j];
$string [$j] = $tmp;
}
return $string;
}
$str = "1234567890";
$new _str = Splitstrwithcomma ($STR);
Echo $new _str. "\ n";
I hope this article will help you with your PHP program design.