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.
nriddockAsked:
Who is Participating?
 
Ivo StoykovConnect With a Mentor Commented:

OK  nriddock

please try this

$lastname = substr($row_Recordset1['Employee'], 0, strpos($row_Recordset1['Employee'], ','));  
0
 
Ivo StoykovCommented:
Hello nriddock ,

try

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

HTH

!i!
0
 
nriddockAuthor Commented:
Parse error: parse error in /var/www/html/php/project_status.php on line 135
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Ivo StoykovCommented:


sorry should be

$lastname = substr($row_Recordset1['Employee'], 0, strpos($row_Recordset1['Employee'], ',')-1);  
0
 
nriddockAuthor Commented:
comma is gone...but now its stripping off the last letter of their name
0
 
nriddockAuthor Commented:
that worked!!!

thanks for all your help.
0
 
Ivo StoykovCommented:
welcome and good luck ;-)

!i!
0
All Courses

From novice to tech pro — start learning today.