elfeste Posted March 10, 2008 Share Posted March 10, 2008 Does anyone know how to trim a result to the first word only. For example John Brown to John Cat in a hat to Cat Tia Quote Link to comment https://forums.phpfreaks.com/topic/95459-seleting-the-first-word-in-a-result/ Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 <?php <?php $data = "John Brown"; $data = "Cat in a hat"; if (preg_match('/(\w+)/i', $data, $regs)) { $firstword= $regs[1]; } echo $firstword; ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/95459-seleting-the-first-word-in-a-result/#findComment-488669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.