jeff5656 Posted June 17, 2009 Share Posted June 17, 2009 Hi I am not well versed in regular expression. I have in the $patient field, "smith, john" Using preg_match, how would I write it so it only echo out Smith? In other words, echo everything up to the comma. Thanks! Link to comment https://forums.phpfreaks.com/topic/162670-preg_match-question/ Share on other sites More sharing options...
MadTechie Posted June 17, 2009 Share Posted June 17, 2009 RegEx isn't required here, so i posted a non-regEx version as well $patient = "smith, john"; if (preg_match('/(.*?),/sim', $patient, $regs)) { $fName = $regs[1]; } echo $fName; //OR echo substr($patient, 0, strrpos($patient, ",")); hope they helps (oh both are untested) Link to comment https://forums.phpfreaks.com/topic/162670-preg_match-question/#findComment-858493 Share on other sites More sharing options...
Ken2k7 Posted June 18, 2009 Share Posted June 18, 2009 ucwords may be useful as well. Link to comment https://forums.phpfreaks.com/topic/162670-preg_match-question/#findComment-858643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.