This has to be a very basic technique, but I'm not finding it in my books or on the web.

I have this :

$firstName = 'John'
$lastName = 'Doe'

I want to get 'J. Doe'

How do I pull the 'J'?

Thanks

Tim

    [man]substr[/man]

    $firstName = "John"; 
    $lastName = "Doe";
    
    //usage
    $fname = substr($firstName, 0, 1);
    $name = $fname.". ".$lastName;
    echo $name;
    

      Isnt this much better?

      $fullname = $firstname{0}.'. '.$lastName;

        Yeah, I wasn't even thinking about the various values of the string itself being in an array like that.... That is much easier. I use the substr so often in search engines I build that I wasn't even thinking about individual strings like this. LOL 😃

          Write a Reply...