IPB

ISO Image Creator

Welcome Guest ( Log In | Register )

> PHP number splitter, splits numbers eg. 1,000
Mackins
post Sep 18 2005, 11:03 AM
Post #1


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


lol. I just spent ages creating a script that would format numbers by putting commas in for the thousands separator until I realised there was a much, much easier way to do it. Anyway, just to show you what I found, here it is:

CODE
<?php
$str = '12345678910; // End result should be: 12,345,678,910
$it = strrev($str) // Reverse the string
$arr1 = str_split($it, 3); // Split into array with chunks of 3
foreach($arr1 as &$value) {
$value = strrev($value); // Reverse each string in the array
}
$arr1 = array_reverse($arr1); // Reverse array once more
echo implode(',', $arr1); // Implode array with a comma as a separator and show to browser


-Mackins cool.gif
Go to the top of the page
 
+Quote Post

Posts in this topic
Mackins   PHP number splitter   Sep 18 2005, 11:03 AM
djbe   uhm, maybe a more simple way to do it: <?php ...   Oct 7 2005, 11:36 AM


Reply to this topicStart new topic
1 User(s) are browsing this forum (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2012 - 01:46 PM

  Page top

Webber Enhanced skin created by Im4eversmart of RuneHQ.

  Privacy Policy 1 2 3 4 5

IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here