Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display data from database with space in php

Tags:

php

mysql

How to show data from my database, but with space in it? I have data "6285398980808" on my database, but i want to show it like "62 853 9898 0808". Any suggestion greatly appreciated.

like image 205
Anditya Pratama Avatar asked Jun 23 '26 19:06

Anditya Pratama


2 Answers

If your number fixed as 13 digits number than you can use preg_replace() as:

<?php
//62 853 9898 0808 required
$number = 6285398980808;

$formatted_number = preg_replace("/^(\d{2})(\d{3})(\d{4})(\d{4})$/", "$1 $2 $3 $4", $number);
echo $formatted_number; // 62 853 9898 0808
?>
like image 119
devpro Avatar answered Jun 25 '26 11:06

devpro


There is a special function for that number_format - just play with parameters.

like image 43
skz Avatar answered Jun 25 '26 11:06

skz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!