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?
yes
just call
explode(' ',$s, 2)
this will create an array with at most 2 elements
I'm assuming you mean a space character for this answer. instead of thinking in terms of explode()
you should think in terms of "find the first character and split the string there."
$pos = strpos($inputString, ' ');
$part1 = substr($inputString, 0, $pos);
$part2 = substr($inputString, $pos+1);
An alternative to explode
$str = 'Hello This is a String';
$parts = preg_split('/(\s)/', $str, PREG_SPLIT_DELIM_CAPTURE);