$data = preg_replace('/(\d)(?=(\d\d\d)+(?!\d))/', '$1.', $data);
preg_replace
function is used to perform a regular expression search and replace operation on the $data
string. The regular expression pattern (\d)(?=(\d\d\d)+(?!\d))
matches a digit (\d
) followed by every three digits ((\d\d\d)+
), as long as it is not followed by another digit ((?!\d)
). The matched digits are then replaced with the digit ($1
) followed by a dot (.
)./
delimiters used in JavaScript regular expressions are not required. Additionally, the g
flag to perform a global search is not needed in PHP, as preg_replace
by default replaces all occurrences of the pattern.