$months="Jan, Feb, Mar, Apr, May, Jun, July, Aug, Sep, Oct, Nov,Dec";
$mn=split(",",$months);
echo "$mn[2]<br>";
echo "$mn[3]<br>";
We 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.
array split (string pattern, string string [, int limit])
We can specify ( option )the limit of breaking required.
$arr=split("/",$mytime); // splitting the array
$mm=$arr[0]; // first element of the array is month
$dd=$arr[1]; // second element is date
$yy=$arr[2]; // third element is year
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.
$input = "apple,banana,orange";
$fruits = explode(",", $input);
print_r($fruits); // Output: Array ( [0] => apple [1] => banana [2] => orange )
$input = "";
$result = explode(",", $input);
print_r($result); // Output: Array ( [0] => "" )
$str = "PHP";
$exploded = explode(" ", $str); // No space, so output is entire string
print_r($exploded);
echo "<br>";
$splitted = str_split($str); // Splits by each character
print_r($splitted);
Output
Array ( [0] => PHP )
Array ( [0] => P [1] => H [2] => P )
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.