lisovaccaro
lisovaccaro

Reputation: 33956

How do I cut a string in half?

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

Answers (2)

casablanca
casablanca

Reputation: 70701

list($first, $second) = explode('    ' /* 4 spaces */, $_GET['s']);

Upvotes: 4

Jonah
Jonah

Reputation: 10091

$value = explode('    ', $_GET['s'], 2);

echo $value[0]; // food
echo $value[1]; // drink

Reference: http://php.net/explode

Upvotes: 4

Related Questions