blacknight Posted August 26, 2006 Share Posted August 26, 2006 ok i need to format a number string foing from the right say example62500 need to be formated to 6 25 00 reasion for being this is for a game site where the 00 is lesser then the 25 and the 6 can go as high as 9999 any ideas? Quote Link to comment Share on other sites More sharing options...
Zane Posted August 26, 2006 Share Posted August 26, 2006 ...what...?so according to you, you want 99992524 to be formatted to 9999 25 24?and use the same code to change62500 to 6 25 00am I correct? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 As long as 25 is in range of 00-99 then this should work:[code=php:0]<?php$num = '62500';// reverse the number so we can work right to left$num_rev = strrev($num);// format the number// number fomrat in reverse// xx yy zzzz$num_format_rev = preg_replace("/([0-9]{2})([0-9]{2})([0-9]{1,4})/", "$1 $2 $3", $num_rev);// now reverse the formated number$num_formated = strrev($num_format_rev);// disply the number:echo 'Old: ' . $num . "<br />\n";echo 'New: ' . $num_formated;?>[/code] Quote Link to comment Share on other sites More sharing options...
blacknight Posted August 26, 2006 Author Share Posted August 26, 2006 ok that achived the desired affect now to go farther is there a way to seperate the numbers in to there own veriables like $var1 $var2 $var3 ? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 Yes use list and explode like so:[code=php:0]list($num1, $num2, $num3) = explode(" ", $num_formated);echo 'Number 1: ' . $num1 . "<br />\n";echo 'Number 2: ' . $num2 . "<br />\n";echo 'Number 3: ' . $num3 . "<br />\n";[/code]That replaces this:[code=php:0]// disply the number:echo 'Old: ' . $num . "<br />\n";echo 'New: ' . $num_formated;[/code] Quote Link to comment Share on other sites More sharing options...
blacknight Posted August 26, 2006 Author Share Posted August 26, 2006 ok we got er thanks guys we needed this for a world of warcraft guild page for reward money for quests :) the fancarian solution thanks you Quote Link to comment Share on other sites More sharing options...
blacknight Posted August 27, 2006 Author Share Posted August 27, 2006 ook we finaly hit a snage when a veriiable id 4 characters or less it automaticalyt asumes its all one number is there a fix for teisso5525 reads as 55 25 not 5525 as the first number where 55 should be the second and 25 the 3rd and the 1st being empty? Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 27, 2006 Share Posted August 27, 2006 You need to explain just what rules you want to be followed in all circumstances. Reading your first post - '6 can go as high as 9999' - but now you can have a 4-digit number that ought to be split into two numbers, not three. You might want to reconsider how the numbers are formatted and de-limit them in the first place as the 'rules' for how to split them sound arbitrary. Quote Link to comment Share on other sites More sharing options...
blacknight Posted August 27, 2006 Author Share Posted August 27, 2006 yes i understand the numbers axualt represent money being 9999 gold peaces 99 sulver and 99 bronze being the most someone can get and 1 bronze being the least i will see what i can figure out from the code given to me... Quote Link to comment Share on other sites More sharing options...
Zane Posted August 27, 2006 Share Posted August 27, 2006 you should just be able to have a defaulted number patternlike 00000000and then just extract it like you are so you'll never have a 4 character line Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.