number_format (1234.567); //Returns the number 1,235 number_format (1234.567, 2); //Returns the number 1,234.57 number_format (1234.567, 2, ',', ' '); //Returns the number 1 234,57 number_format (1234.567, 1, 'a', 'b'); //Returns the number 1b234a6
Friday, October 7, 2011
Use number_format() function in PHP
You can use the PHP function number_format to format a number in several ways, including choosing how many decimal points it will have, and choosing the 1000s, and decimal point dividers. It is phrased as number_format ( your_number , optional_decimals , optional_decimal_point, optional_1000_separator ) You can not specify just the decimal point or 1000 separator, if you specify one you need to specify both. When working with decimals, it will function like round () and put things at or over .5 up, and under .5 down.
Problem with javascript replace() function
Suppose we have a string: "The horse kicks the stony horse". Using javascript replace() function, we want to replace 'horse' by 'cow'.
and the result of replaced_str is "The cow kicks the stony horse" ... surprise!
The replace() function replaced only the first string which was found and ignore others. What we should do?
Regex is a way to solve it, instead
and the replaced_str should be "The cow kicks the stone cow".
str = "The horse kicks the stony horse"; replaced_str = str.replace('horse', 'cow');
and the result of replaced_str is "The cow kicks the stony horse" ... surprise!
The replace() function replaced only the first string which was found and ignore others. What we should do?
Regex is a way to solve it, instead
replaced_str = str.replace('horse', 'cow');We use
replaced_str = str.replace(/horse/g, 'cow');
and the replaced_str should be "The cow kicks the stone cow".
Thursday, October 6, 2011
Install PHP on Windows, Linux, MacOS
This post is about how to install a ready-working PHP environment on different OS.
Personally, I prefer a full package to install one by one package. This mean, there're some pre-built solution for PHP, MySQL, Apache just install and run.
For Windows machine, download Appserv, install and got everything people want to start working with PHP.
MacOS, after a few days struggle with package installation, I found MAMP is acceptable.
Linux, here are a good guide
Moreover, you may want to build a virtual machine (CentOS for example) on Windows machine. Download and install PHP, mysql, apache on that centos, and then access it from your Windows machine. This will let you use eclipse on windows to modify the source on run on centos. It's good in some ways, especial to people who stick with windows but still want to use PHP on Linux.
Personally, I prefer a full package to install one by one package. This mean, there're some pre-built solution for PHP, MySQL, Apache just install and run.
For Windows machine, download Appserv, install and got everything people want to start working with PHP.
MacOS, after a few days struggle with package installation, I found MAMP is acceptable.
Linux, here are a good guide
Moreover, you may want to build a virtual machine (CentOS for example) on Windows machine. Download and install PHP, mysql, apache on that centos, and then access it from your Windows machine. This will let you use eclipse on windows to modify the source on run on centos. It's good in some ways, especial to people who stick with windows but still want to use PHP on Linux.
Tuesday, October 4, 2011
Prepare the environment for PHP programming
This post aims to developer, who is familiar with programming but has less experiences with PHP. Here you can see what need to do to start working with PHP.
Operation system
PHP can be mostly installed in Windows (all version), Linux (all version), MacOS. As my observer, Linux gives the best performance and suitable for both junior and advance PHP programmer.
IDE
There're many IDE for PHP programming, most of them do the good job. I prefer PDT to others, because it's eclipse's plugin and support syntax highlight, indentation, good completion.
Aside from that, PDT is acceptable for HTML/CSS/Javascript editing.
What to do
Here comes the list of what need to do
Create some project, find sample code, and start working. You'll learn a lot while dealing with real problem.
Operation system
PHP can be mostly installed in Windows (all version), Linux (all version), MacOS. As my observer, Linux gives the best performance and suitable for both junior and advance PHP programmer.
IDE
There're many IDE for PHP programming, most of them do the good job. I prefer PDT to others, because it's eclipse's plugin and support syntax highlight, indentation, good completion.
Aside from that, PDT is acceptable for HTML/CSS/Javascript editing.
What to do
Here comes the list of what need to do
- download and install Webserver, Apache is good for all of us, but you may want to try Ngnix
- download and install PHP. It's vary from OS.
- download and install database system, MySQL is good for start. Next time you may want to try some NoSQL
- config your webserver to support mod rewrite and install the necessarily library for connecting PHP to database server.
Create some project, find sample code, and start working. You'll learn a lot while dealing with real problem.
Monday, September 27, 2010
setting environment PATH in ubuntu
open file /etc/environment and edit it, this change only affects the new sell. If you wanna apply change for current sell, do this: "
export PATH="${PATH}:"
Tuesday, September 14, 2010
reinstall grub on MBR
from ubuntu 9.10, grub 2 is installed by default.
if for some reasons, you installed windows after ubuntu on your machine, grub gone.
one of the ways to get your ubuntu back is reinstall grub on MBR. follow these steps
if for some reasons, you installed windows after ubuntu on your machine, grub gone.
one of the ways to get your ubuntu back is reinstall grub on MBR. follow these steps
- boot from an ubuntu livecd.
- open terminal, type sudo -i
- fdisk -l and find the partition where located linux
- mkdir /media/root
- mount /dev/sda(x) /media/root
- grub-setup --root-directory=/media/root -m /media/root/boot/grub/device.map /dev/sda(x)
Wednesday, June 2, 2010
how to use slug with django
2 options
on Admin
create a slug = models.SlugField(max_length = 200) in model
on Admin
create a slug = models.SlugField(max_length = 200) in model
class ClientAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('name',)} admin.site.register(Client, ClientAdmin)
or
class test(models.Model): q = models.CharField(max_length=30) s = models.SlugField(editable=False) # hide from admin def save(self): if not self.id: self.s = slugify(self.q) super(test, self).save()
Subscribe to:
Posts (Atom)