Im just wondering if there a way to write this code in just one line.
$exp = explode(" ", $text);
$cut = $exp[0];
So without having to assign variables.
Thanks
If you only ever want the first part, then avoid the array workaround with strtok
:
$cut = strtok($text, " ");
It cuts out something from the string until the first delimiter (space in your case).
$cut = preg_replace('/ [\s\S]*$/', '', $text);
http://codepad.org/yujJRnYS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With