Tutorial: Solve PHP function split() is deprecated

Solve PHP function split() is deprecated

To solve the deprecated warning (occurring since PHP 5.3) with the split function you have two possibilities, depending what you try to split with the built-in function.











Simple string splitting



<?php
$splitted = split(':', 'username:password');

// Replace it like that

$splitted = explode(':', 'username:password');

In the most cases you try to split by a simple string, then you could replace the current split with explode (fastest possibility).


Splitting by regular expression



<?php
$splitted = split(':', 'username:password');

// Replace it like that

$splitted = preg_split('/[s]+/', 'Another simple replacement');

In case you split a string not by a simple string but instead by a regular expression you could use the preg_split.



If you have further questions: Just use the comments section below.


This website was archived in July 2024. It is now read-only and might be eventually taken offline.