Add comma to php

Asked

Viewed 31 times

0

would like to add a "," after the first two numbers. For example: 2098 -> 20.98; 20398 -> 20,398; 201 -> 20,1; Does anyone know how to do this in php?

1 answer

2


You can do it like this:

echo preg_replace('/^(..)/', '$1,', '2098'); // 20,98

You can read more about preg_replace here.

And regular expressions here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.