Search results
11 maj 2012 · 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.
PHP has a function called preg_split() splits a string using a regular expression. This should do what you want. Or explode() might be easier. $str = "44-xkIolspO"; $parts = explode("-", $str); $one = $parts[0]; $two = $parts[1];
Returns an array of string s created by splitting the string parameter on boundaries formed by the separator. If separator is an empty string (""), explode () throws a ValueError.
split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode() , which doesn't incur the overhead of the regular expression engine.
To get around this you can instead use preg_match_all() to perform the split. For comparison, here are two examples, both splitting around colon and semi-colon characters: <?php $pieces_with_delimiters = preg_split ('/[;:]/', $input, - 1, PREG_SPLIT_OFFSET_CAPTURE); ?> <?php preg_match_all ('/([^;:]*)([;:]|$)/', $input, $matches);
Learn how to replace the deprecated PHP split function with modern alternatives like explode() and preg_split(). This guide covers performance, use cases, and best practices for secure and efficient string operations in PHP.
str_split() will split into bytes, rather than characters when dealing with a multi-byte encoded string. Use mb_str_split() to split the string into code points.