How to check how many characters in variable, and add space between characters in that var?

Problem :

I have a 'price' variable that contains some integer number from a MySQL database.

I want to check how many numbers the 'price' variable contains, and add a space in the variable depending on how many numbers. See below:


If 'price' is 150000 I would like the output to be 150 000 (notice the space). OR, if it is 19000 I would like it to output 19 000...

How would you do this the easiest way?

Solution :

The easiest way is to use number_format():

$str = number_format($number, 0, '.', ' ');

Mysql Tutorials

Mysql Howto..

how to use sum and count (both) in mysql

How to decrease the searching time in MySQL DB when searching for a range of dates?

How to compare 2 mysql table with a primary key in [closed]

How to use “mysql2” gem in Rails 3 application on Windows 7?

Ruby MySQL Gem Can't Find Locate Mysql Socket (how to assign location)

How to find the sum of two colums with a quantity value

How to use TIME type in MySQL?

How to find root cause for “too many connections” error in MySQL/PHP

How can I break the tie from my MySQL query using PHP?

How to Display top search terms from a MySQL database and grouped by date

how to select mysql query with foreign language?

How to get the intersection of two columns

how to remove special characters (ex:Montréal-Rive-Sud) from mysql databse

How to make Mysql variables work in a query

Simple mysql function help: how to store a function, use it to manipulate data and write data to new table

How do I check a MySQL column to make sure it contains a value?

How to get sum slalry year by year using SQL query?

how to backup and restore mysql database (localhost) to cloud service in PHP [closed]

How to create a login for clients?

How to safely connect to a database [closed]

How to send query to populate utf8 VARCHAR column using Connector/C++?

Wireshark how do i know if packet is encrypted?

How to build a Docker container with a running MySQL?

mysql - how to get all differences from one table to another (huge amount of rows ~ 500k)

Mysql workbench shows wrong database instances

How to implement a nested comment system?

How to shorten mySQL queries with PDO?

MySQL query how to get list of all distinct values from columns that contain multiple string values?

How to combine two query in single query in mysql byusing subquery or inner query

How to migrate from Oracle RDB for OpenVMS to MySQL in Windows?