PHP is telling me that split is deprecated, what's the alternative method I should use?
Assuming you are using UTF-8 (or you can convert it to UTF-8 using Iconv or some other tools), then using the
u modifier (doc: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php )
<? $s = "FrontPage 2000???????"; print_r(preg_match_all('/./u', $s, $matches)); echo "n"; print_r($matches); ?>
21 Array (  => Array (  => F  => r  => o  => n  => t  => P  => a  => g  => e  =>  => 2  => 0  => 0  => 0  => ?  => ?  => ?  => ?  => ?  => ?  => ? ) )
Note that my source code is stored in a file encoded in UTF-8 also, for the $s to contain those characters.
The following will match alphanumeric as a group:
<? $s = "FrontPage 2000???????"; print_r(preg_match_all('/(w+)|(.)/u', $s, $matches)); echo "n"; print_r($matches); ?>
10 Array (  => FrontPage  =>  => 2000  => ?  => ?  => ?  => ?  => ?  => ?  => ? )
Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):
$ pecl -d php_suffix=5.6 install <package> $ pecl uninstall -r <package> $ pecl -d php_suffix=7.0 install <package> $ pecl uninstall -r <package> $ pecl -d php_suffix=7.1 install <package> $ pecl uninstall -r <package>
-d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with
pecl config-set. The
uninstall -r bit does not actually uninstall it (from the docs):
vagrant@homestead:~$ pecl help uninstall pecl uninstall [options] [channel/]<package> ... Uninstalls one or more PEAR packages. More than one package may be specified at once. Prefix with channel name to uninstall from a channel not in your default channel (pecl.php.net) Options: ... -r, --register-only do not remove files, only register the packages as not installed ...
The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).
preg_split() is similar to the old ereg-function split(). You only have to enclose the regex in
/.../ like so:
preg_split('/www/', 'D:/Projects/job.com/www/www/path/source', 2);
The enclosing slashes
/ here are really part of the regular expression syntax, not searched for in the string. If the
www delimiter is variable, you should additionally use preg_quote() for the inner part.
But note that you don't need regular expressions if you only look for static strings anyway. In such cases you can use
explode() pretty much like you used split() before:
explode('www', 'D:/Projects/job.com/www/www/path/source', 2);
Never used any of those, but they look interesting..
Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..
explodeis an alternative. However, if you meant to split through a regular expression, the alternative is