I'm just wondering if there is a way to write this code in only one line.
$exp = explode(" ", $text); $cut = $exp[0];
Thus, without the need to assign variables.
thank
If you need only the first part, then avoid traversing the array with strtok:
strtok
$cut = strtok($text, " ");
It cuts something from the line to the first delimiter (space in your case).
$cut = preg_replace('/ [\s\S]*$/', '', $text);
http://codepad.org/yujJRnYS
$var = reset(explode(" ", $text));
$cut = substr ( $text, 0, strpos ( $text, ' ' ) );
OR
$cut = substr ( trim ( $text ), 0, strpos ( trim ( $text ), ' ' ) );