Welcome to Server Circle. It's a friendly site and all levels of experience are welcome. Be aware that we use cookies for your login.
Server Circle - Ask questions about Servers and get answers from experts.
Beta (0.73 sec)
PHP question: how do I get the first character from a string in PHP ?

http://php.net/manual/en/function.substr.php

I can't see it on this page other than this which doesn't work.

$first = $var[0]; echo $first[0];

Thank you.

Asked by:
Kenobi
680 points
 Report Abuse
 Share Page - Category: Programming - Tags: PHP question: how do I get the first character from a string in PHP ?
 Enter your response
Please use Pastie.org to paste lengthy code or to fix formatting issues with code
  • Responses in reverse (1)

That should work assuming there's something in the $var variable. Maybe try $var = trim($var); first and then run the above to make sure it's got something printable.

Alternatively, try substr() with something like:

$var = trim($var);

$first = substr($var, 0);

echo $first;


(Sorry the the late reply - only just spotted this one).

Response by:
trevHCS
640 points


  • Related Questions
About Us : Contact Us : Etiquette : Terms : CDN Failover : ShorterURL : CDN Fallback : © 2013 Server Circle