Link to home
Start Free TrialLog in
Avatar of nriddock
nriddockFlag for United States of America

asked on

simple preg_replace question - remove everything after the comma - inc. the comma

I have a database field "$row_Recordset1['Employee']" that contains lastname, firstname. I want to strip out everything after the , (including the ,) so that it only displays lastname. Im having difficulty getting preg_replace to do what i want. its still displaying the comma

$lastname = preg_replace('/^([^ ]+).*/','\1', $row_Recordset1['Employee']);

any suggestions? Thanks.
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Hello nriddock ,

try

$lastname = substr($row_Recordset1['Employee'], 0, strpos($row_Recordset1['Employee']), ',')-1);  

HTH

!i!
Avatar of nriddock

ASKER

Parse error: parse error in /var/www/html/php/project_status.php on line 135


sorry should be

$lastname = substr($row_Recordset1['Employee'], 0, strpos($row_Recordset1['Employee'], ',')-1);  
comma is gone...but now its stripping off the last letter of their name
ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that worked!!!

thanks for all your help.
welcome and good luck ;-)

!i!