How to String Replace Comma With Dot in PHP?

03-Apr-2023

.

Admin

How to String Replace Comma With Dot in PHP?

Hi Dev,

This article will provide example of How to string replace comma with dot in PHP. this example will help you replace comma with a dot in the number. this example will help you replace all comma with dot PHP example. you'll learn Program to replace the comma with dot using PHP. You just need to some step to done string replace regex function in PHP code.

Example: 1


index.php

<?php

// Declare a string

$ip = "134.645.478.670";

// Declare a regular expression

$regex = "/\./";

$output = preg_split ($regex, $ip);

echo "$output[0] <br>";

echo "$output[1] <br>";

echo "$output[2] <br>";

echo "$output[3] <br>";

?>

Output:

134

645

478

670

Example: 2

index.php

<?php

// Declare a regular expression

$regex = "/<b>(.*)<\/b>/U";

// Declare a string

$inputString = "Name: <b>John</b> Position: <b>Developer</b>";

preg_match_all($regex, $inputString, $output);

echo $output[0][0]." <br> ".$output[0][1]."\n";

?>

Output:

John

Developer

I hope it could help you...

#PHP