Jump to content

HOW TO REDUCE NAME TO INITIAL...


cgus

Recommended Posts

Trying to output only the first character of a name in a field -- like, "Andrew" would output as "A."

 

I have this:

 

<?php echo $row_rs1[left('fname', 1)]; ?>

 

It does not work, but causes this error:

 

Fatal error: Call to undefined function LEFT() in....

 

Any guidance will be appreciated!

 

Link to comment
https://forums.phpfreaks.com/topic/295946-how-to-reduce-name-to-initial/
Share on other sites

Thanks for your responses.  I tested the suggestions by Guru and Administrator.  Both work perfectly.

 

PHP to get only the first character in a string to output.

Example:  "Andrew" outputs to "A"

 

<?php echo substr($row_rs1['fname'], 0, 1); ?>

Tested this and it works.

 

$myString = "abcdefg";

echo $myString[0];  //will echo ==> a

Tested this, and it also works.  Implemented as:

<?php echo $row_rs1['fname'][0]; ?>

 

Grateful!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.