Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split() deprecated [duplicate]

Tags:

php

Possible Duplicate:
PHP split alternative?

 // Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
 $lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];

Hello People, this is a part of my geolocation code. I try to change a stored adress into a lat/long and than save the lat/long back in the database. They use the split function to put a string in an array but since php 5.3.0 the function is deprecated. Anyone has a solution for this?

Thank you

EDIT:

When i use this

$coordinatesSplit = preg_split(",", $coordinates);

I receive following error

preg_split() [function.preg-split]: No ending delimiter

LAST edit When i add something to the database, the long/late are automatically saved to. But when i want to add for example the 6th adress in the database, the script to generate the lat/long is automatically doing this over all the records in the database. Is there any posibility to do this only at the last added? ----> Geolocation LONG/LAN in database

like image 982
Niels Avatar asked May 10 '12 23:05

Niels


2 Answers

You can get simpler code with:

list($lat,$lng) = explode(",",$coordinates);

This directly assigns the result of explode into the two variables for you.

like image 62
Niet the Dark Absol Avatar answered Nov 08 '22 07:11

Niet the Dark Absol


As discussed in the comments, use explode() instead:

$coordinatesSplit = explode(",", $coordinates);
like image 41
Michael Robinson Avatar answered Nov 08 '22 06:11

Michael Robinson