How to split 4113.52318N into two parts in php

advertisements

I want to split 4113.52318N in two parts like 41 and 13.52318N And after that I want to remove N from the second value.

any help please?


There are several ways to do this, one is with preg_match_all, i.e.:

<?php
$string = "4113.52318N";
$result = preg_match_all('/^(\d{2})([\d.]+)/', $string, $matches);
$partOne = $matches[1][0]; //41
$partTwo = $matches[2][0]; //13.52318


Ideone Demo