Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split php string by colon using split

Tags:

php

I wanted to do something like this:

list($hour, $minute) = split("/:/", $departure_time);

however it says split() is deprecated why is this? What am I doing wrong?

like image 542
xonegirlz Avatar asked Dec 27 '22 10:12

xonegirlz


2 Answers

split belongs to the ereg class functions, which have been superseded by preg_match and preg_split.

You should be using explode() anyway, since you only have a static string, not an actual matching pattern with variable placeholders.

like image 122
mario Avatar answered Jan 11 '23 13:01

mario


Use explode() instead of split().

like this:

$array = explode(':', $string);
like image 43
Yes Barry Avatar answered Jan 11 '23 13:01

Yes Barry