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 related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

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

Comments are closed.

Featured Sponsors

About


Advertisements