Split a String Conversion into php array
The explode() function is used to split a string.
sometimes required to convert strings into PHP array. I’ll tell how to use it with examples PHP explode().
explode() function used when we need to split a string using a specific character or string present in that string.
Syntax
explode(separator,string,limit)
The “separator” and “string” parameter cannot be an empty string.
The limit parameter is an Optional. Specifies the number of array elements to return.
See below example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php $data="Hello world. It's a beautiful day."; $split=explode(" ",$data); foreach ($split as $key => $value) { echo "split[".$key."] = ".$value."<br>"; } //output // split[0] = Hello // split[1] = world. // split[2] = It's // split[3] = beautiful // split[4] = day. ?> |
Please follow and like us: