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 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; ?> ?> 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
Archived
This topic is now archived and is closed to further replies.