scriptygoddess

26 Feb, 2003

Get first (part of) name

Posted by: Jennifer In: Script snippet

(non blog related post) Needed to use this php function: strchr (alias to strstr).

I had a field that had a person's full name (first and last). 99.999% of the time, the first name and last name were seperated by a space (no Mr. or Mrs. in there) and I needed a script that assumed as such and grabbed what was more than likely the person's first name. I found the script below on that strchr function page.

<?php
$fullname = $row['customername'];
$toFind = " ";
echo str_replace( strchr($fullname, $toFind), "", $fullname );
?>

so if $row['customername'] was "Jane Smith"… the script above would return just "Jane"

No Responses to "Get first (part of) name"

Comments are closed.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements