Web Hosting Talk







View Full Version : php problem...


MGCJerry
06-01-2002, 09:58 PM
I know this can be done, cause I see it here. I'm writing a php script, and with a particular result (very high number) I'd like to have commas in it, but I dont know how to start...

Here is some of the code, the resulting number for "$gnp" is up into the billions, and I'd like to to be easer read with some commas in the final result (ex 1,234,787,764.66). I know this is possible because I see it every day on WHT (example on WHT homepage: Total Threads: 50,854).

This script generates a page that can be directly entered into my nuke site. This is one of many "conversion" scripts I have written which helps me paste the HTML data into my site's database. The "Encyclopedia" in phpnuke doesnt like any spaces between any HTML tags (which makes WYSIWYG editors out of the question as I had to manually delte all spaces between all HTML tags). If you ever used php-nuke and wanted tables in the "Encyclopedia", you'll know what I mean ;).


<?PHP

include("includes/planet.txt");

$pop = $adrothian + $forestinian + $helfin + $human +
$hydratie + $isitolie + $leenin + $magmadon + $morsenian +
$phayon + $quizorthian + $sarian + $septian + $sivadffejian +
$zelenitorian + $other;

$gnp = $income * $pop;

print "<title>Conversion for $pltname</title>\n";

$tmpl_file = "includes/pltemp.html";
$thefile = implode("", file($tmpl_file));
$thefile = addslashes($thefile);
$thefile = "\$r_file=\"".$thefile."\";";
eval($thefile);
print $r_file;

?>


Any help would to add commas to the result for "$gnp" be really appreciated. The script is run locally so the processing time isn't too important.

Edit I had to put the equation for "$pop" on different lines so you wouldnt need to scroll waaaaaaaaaaaaay to the right ;)
/edit

acetate
06-01-2002, 11:04 PM
Uhh.. So you want to format the outcome of $gnp to thousands?
Simply use the function number_format()

You can find more info here:http://www.php.net/manual/en/function.number-format.php

MGCJerry
06-01-2002, 11:38 PM
*smacks forehead very hard*

I didnt know there was a built in function for that, thanks for referring me back to the php manual. :homer:

Hmmm... makes me wonder what else is buried in that manual. I downloaded the complied HTML documentation (chm). maybe I should stick my face in that manual some more.

1 line of lousy code, and here I was expecting to have to write the function myself.

alpha
06-02-2002, 12:53 AM
if only i got a dime everytime I realized that there was a built-in function or a easily accessible function on the net that could help out some functions that I coded from scratch from the past.... I would have about a $100 so far...

:D