Skip to content
Advertisement

How can Split a String value by PHP? [closed]

i have a string like this :

$string = 'LatLng(35.700585, 51.377027)';

how i can select first section between ‘(‘ and ‘,’ character?

Like :

$x = '35.700585';
$y = '51.377027';

help . thanks

Advertisement

Answer

I think this is what you want:

<?php
$string = 'LatLng(35.700585, 51.377027)';
$newStr = str_replace('LatLng(', '', $string);
$newStr = str_replace(')', '', $newStr);

$arr = explode(',', $newStr);

$x = $arr[0];
$y = $arr[1];

print_r($y);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement