Breaking of strings to create array using split commandWe can break strings to form arrays. We can break by using a pattern or by regular expression. This way we can break strings to create array of string. Here is the syntax.
We can specify ( option )the limit of breaking required.
If we have a string with commas ( , ) between the words then we can break it to form arrays. For example here is a string with name of the months separated by commas. We will try to break this by using split command.
One of the main uses is creating a month date and year from the data entered by the users. Users will enter date in one input box in mm/dd/yy format. We will use this string and break it into three parts storing month, date and year in three different variables for further processing. Here is the code how this works.
We will get the value from the form and the date entered by the user is available in variable $mytime. Where $mytime="05/13/05";
From this date data we can format our date field as per our requirement. Read how the user entered date value is validated by using checkdate function.
split() is DEPRECATED as of PHP 5.3.0, better use string explode
Read how split command is used to separate domain and user id part from an email address
Read how split command is used to count number of words present in text string