2

i want to replace comma from decimal string

For example: i have a text

"Sample content 2.6g ident. 2um the 84.45gm with 2,8g and some 23.83 that it".

Expected output:

 "Sample content 2,6g ident. 2um the 84,45gm with 2,8g and some 23,83 that it".

Please suggest me how to replace comma from decimal in php

1
  • regular expression that searches for digit.digit and replaces it with digit,digit. Don't know how to do it in your language, sorry. Commented Jun 26, 2013 at 17:19

1 Answer 1

2

You can for example test if the comma is surrounded by digits:

$str = preg_replace('~(?<=\d)\.(?=\d)~', ',', $str);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.