Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php explode function for only first white space

Tags:

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?

like image 476
sandbox Avatar asked Feb 22 '12 20:02

sandbox


People also ask

What is the difference between explode () and split () functions in PHP?

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.

What is the difference between explode () and implode () functions with example?

PHP Explode function breaks a string into an array. PHP Implode function returns a string from an array.

How do you seperate a string by space in PHP?

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.

What does the explode () function do?

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.


2 Answers

set limit parameter

print_r(explode(' ', $str, 2));

Reference

like image 187
diEcho Avatar answered Sep 29 '22 09:09

diEcho


yes

just call

explode(' ',$s, 2)

this will create an array with at most 2 elements

like image 20
dweeves Avatar answered Sep 29 '22 10:09

dweeves