I would like to extract a number (4 positions) from a string which is stored in a database.
e.g. "Mountain guesthouse (2340m) in Radons" How is this to be done? It is possible that the number is like 2.340m
I would like to extract a number (4 positions) from a string which is stored in a database.
e.g. "Mountain guesthouse (2340m) in Radons" How is this to be done? It is possible that the number is like 2.340m
<?php
//$string = 'Mountain guesthouse (2340m) in Radons';
//preg_match('#([0-9]+)m#is', $string, $matches);
//$peak = number_format($matches[1], 0, ',', '.');
//EDIT
$string = 'Mountain guesthouse (23.40m) in Radons';
$preg_match('#([0-9\.]+)m#is', $string, $matches);
$peak=$matches[1];
echo $peak . 'm'; # 23.40m
?>
Live: http://ideone.com/42RT4
Edit live: https://ideone.com/hNJxG