This is my source code:
preg_replace('/[A-Z0-9]/', 'X', number_format('1000000'));
Result: x,xxx,xxx
But, I want the result like 1,xxx,xxx, i.e., don't replace the first number.
This is my source code:
preg_replace('/[A-Z0-9]/', 'X', number_format('1000000'));
Result: x,xxx,xxx
But, I want the result like 1,xxx,xxx, i.e., don't replace the first number.
Here are a couple of straightforward ways to do it in JavaScript:
var input = "1,000,000"
var output = input.substr(0,1) + input.substr(1).replace(/\d/g, 'x')
console.log(output)
// or:
var output2 = input.replace(/\d/g, function(m, i) { return i ? 'x' : m })
console.log(output2)
(I assume you can convert at least the first one to PHP with no trouble if you'd rather do it server-side, though you did ask for PHP or JS.)
Please use this code when you are using PHP:
<?php
$number = '1000000';
$x = number_format($number);
echo $result = str_replace("0", "X", $x);
?>