hlstriker Posted April 13, 2007 Share Posted April 13, 2007 Hi, I was wondering how I could get the first letter or number from a variable. I thought maybe with $var[0] but that didn't seem to work for me. EDIT: Nevermind was a different error in my code, BUT how can I make this letter turn lowercase even if its capital? Link to comment https://forums.phpfreaks.com/topic/46873-getting-first-letter-or-number-from-variable/ Share on other sites More sharing options...
kenrbnsn Posted April 13, 2007 Share Posted April 13, 2007 That should have worked. You can also do <?php $str = 'This is a test'; $first_letter = substr($str,0,1); ?> Ken Link to comment https://forums.phpfreaks.com/topic/46873-getting-first-letter-or-number-from-variable/#findComment-228521 Share on other sites More sharing options...
hlstriker Posted April 13, 2007 Author Share Posted April 13, 2007 Thanks alot Ken, it was just a different error in my code. I edited my first post because I had another question to go along with this. Link to comment https://forums.phpfreaks.com/topic/46873-getting-first-letter-or-number-from-variable/#findComment-228523 Share on other sites More sharing options...
kenrbnsn Posted April 13, 2007 Share Posted April 13, 2007 Use strtolower() Ken Link to comment https://forums.phpfreaks.com/topic/46873-getting-first-letter-or-number-from-variable/#findComment-228526 Share on other sites More sharing options...
boo_lolly Posted April 13, 2007 Share Posted April 13, 2007 you can also do: <?php $str = 'This is a test'; $first_letter = $str[0]; ?> Link to comment https://forums.phpfreaks.com/topic/46873-getting-first-letter-or-number-from-variable/#findComment-228538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.