Posted By

dego89 on 03/14/13


Tagged

php with starts lastname


Versions (?)

first letter of lastname php


 / Published in: PHP
 

Get the first char of a lastname in php

  1. <?php
  2. $mystring = 'Test Name';
  3. $findme = ' ';
  4. $pos = strpos($mystring, $findme);
  5.  
  6. // The !== operator can also be used. Using != would not work as expected
  7. // because the position of 'a' is 0. The statement (0 != false) evaluates
  8. // to false.
  9. if ($pos !== false) {
  10. $ln = substr($mystring, $pos, 2);
  11. echo "Last name starts with ". trim($ln, " ")."";
  12.  
  13. } else {
  14. echo "The string '$findme' was not found in the string '$mystring'";
  15. }
  16. ?>

Report this snippet  

You need to login to post a comment.