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


  • Michael: You can use get_header(2) in your case. The filename of your custom header has to be header-2.php. The problem with include(your_file.php) is, all
  • cliff: hi wonder if you can help me, pls i designed www.kouga.mobi using dreamweaver CS3 and now want to make the phonenumbers into links so that if you
  • jerey: how do i rewrite this because it tried RewriteEngine on #Options +FollowSymlinks RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FIL

About


Advertisements