Reputation: 33956
I want to cut a string in half, and get the first half of the string to be one value the second half to be another.
The string is $_GET['s']
it has a couple of words and in the middle of them four blank spaces.
I want to get the words before the blank spaces and the words after the blank spaces.
E.G:
pizza soda
echo "$food;" ==> pizza
echo "$drink; ==> soda
Upvotes: 0
Views: 343
Reputation: 70701
list($first, $second) = explode(' ' /* 4 spaces */, $_GET['s']);
Upvotes: 4
Reputation: 10091
$value = explode(' ', $_GET['s'], 2);
echo $value[0]; // food
echo $value[1]; // drink
Reference: http://php.net/explode
Upvotes: 4