Getting the first word of a string and putting the remainder into another variable
Trying to set the first word of a string as a separate variable and taking the remainder and setting it as separate variable.
list($model, $submodel) = expl开发者_JAVA百科ode(' ', $full);
When I use list and explode I almost get the result I want but instead of the remainder of the string I get the 2nd word.
If you only want to split by the first space and therefore into 2 substrings, pass a limit of 2
to explode()
, like so:
list($model, $submodel) = explode(' ', $full, 2);
Now $model
will contain the first word and $submodel
will contain the rest of the string.
worst case scenario, you can manually get the first word using strpos() to get the space and substr to get the first word and str_replace to get it out of the rest of the string. thats if all the good advices u get don't work.
精彩评论