To split a string into an array of substrings in PHP, you can use the explode()
function. This function splits a string into an array of substrings based on a specified delimiter.
Here's an example:
main.php92 chars5 lines
Output:
main.php79 chars8 lines
In this example, we have a string that contains four fruits separated by commas and spaces. We pass the delimiter ", " (comma and space) to the explode()
function, which splits the string into an array of substrings.
The resulting array contains each fruit as a separate element.
Note: The explode()
function is case-sensitive, so make sure the delimiter you pass to it matches the one in your string.
gistlibby LogSnag