Return to Snippet

Revision: 62819
at March 14, 2013 04:48 by dego89


Initial Code
<?php
$mystring = 'Test Name';
$findme   = ' ';
$pos = strpos($mystring, $findme);
 
// The !== operator can also be used.  Using != would not work as expected
// because the position of 'a' is 0. The statement (0 != false) evaluates 
// to false.
if ($pos !== false) {
    $ln = substr($mystring, $pos, 2);
    echo "Last name starts with ". trim($ln, " ")."";
 
} else {
     echo "The string '$findme' was not found in the string '$mystring'";
}
?>

Initial URL

                                

Initial Description
Get the first char of a lastname in php

Initial Title
first letter of lastname php

Initial Tags
php

Initial Language
PHP