如何使用php或者javascript将1,000,000的价格更改为1,XXX,XXX?

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.)

</div>

Please use this code when you are using PHP:

<?php
$number  = '1000000';
$x = number_format($number);
echo $result = str_replace("0", "X", $x);
?>

Try this.

echo preg_replace('/(?!^)\S/',  'X', number_format('1000000'));