I have a String Hello This is a String
. I need to explode it in PHP only for the First White Space
. How is that possible?
Both the functions are used to Split a string. However, Split is used to split a string using a regular expression. On the other hand, Explode is used to split a string using another string.
PHP Explode function breaks a string into an array. PHP Implode function returns a string from an array.
To split a string into words in PHP, use explode() function with space as delimiter. The explode() function returns an array containing words as elements of the array.
The explode function is utilized to "Split a string into pieces of elements to form an array". The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.
set limit parameter
print_r(explode(' ', $str, 2));
Reference
yes
just call
explode(' ',$s, 2)
this will create an array with at most 2 elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With