PHP: Extracting Decimal from String

In this examples, we will see how to extract the decimal values from the string. For example our string  is $string=”Hello World 786.65″ from this extracting the decimal value 786.65 using PHP Preg_Match() function.

The below is the example code of extracting the Decimal from the string,

$string=”Hello World 786.65″;
preg_match(‘{(\d+\.\d+)}’, $string, $m);
$number = $m[0];
echo $number .”<br/>”;

The  Output will be like this,

786.65

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: