phpBeginner06 Posted January 26, 2007 Share Posted January 26, 2007 Is there a way to use number_format() with a PHP Include that is a text file? I made a script, but it does not echo that right results.[code]<?php$somenumber=include("01-25-2007.txt");$formatted=number_format($somenumber);echo "$formatted";?>[/code]The text file "01-25-2007.txt" contains the number "1000". The script should echo a number like "1,000"; but instead it's echo looks like this: "10001".Is it even possible to use number_format() with a text inlude? If so, what is the best way to go about doing it? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 26, 2007 Share Posted January 26, 2007 That's not how you use the include() function.What does the included file contain?You can do something like this:File test_include.php[code]<?php$somenumber = 1000;?>[/code]Main script:[code]<?phpinclude('test_include.php');$formatted = format_number($somenumber);echo $formatted;?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Monkeymatt Posted January 26, 2007 Share Posted January 26, 2007 You used include() wrong, as kenrbnsn said. You can do what I think you want to this way:[code]<?php$somenumber=file_get_contents("01-25-2007.txt");$formatted=number_format($somenumber);echo "$formatted";?>[/code]Monkeymatt Quote Link to comment Share on other sites More sharing options...
phpBeginner06 Posted January 26, 2007 Author Share Posted January 26, 2007 Monkeymatt, your script did the job - Thanks 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.