I have strings like... \"3/4\" and \"5/9\" and some like... \"1/2 km\" and \"3/4 degree\" stored in mysql columns.
I would like to convert them into numbers. In first c
With PHP you could do:
// assuming $vals has the values from the database
$converted = array();
foreach ($vals as $key => $val) {
preg_match("/^(\\d+)\\/(\\d+)/", $val, $matches)
if (count($matches) > 2) {
$numerator = (int) $matches[1];
$denominator = (int) $matches[2];
$converted[$key] = (float) $numerator / $denominator;
}
}