m67
m67

Reputation: 23

Truncate Output of Field Php

I have a call to the database for this row:

echo "{$row['uLName']}";

This would output for example say : "Smith"

How do I get this call to just output "S" or whatever the first letter is of the output using php?

Thanks

Upvotes: 0

Views: 412

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270609

A simple call to substr():

echo substr($row['uLName'],0,1);

Or by string index, since a string's characters can be accessed by numeric array index.

echo $row['uLName'][0];

Upvotes: 3

Related Questions