want to take the first letter from a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blindleaf
Forum Newbie
Posts: 6
Joined: Thu Jun 16, 2005 9:36 am

want to take the first letter from a string

Post by blindleaf »

I am trying to create links to another website that has directories in the format: http://www.website.com/t/the_vines/ and I have links on my website that have "the vines" part and i want to link to that format but i need to be able to find the first letter from the band name string and store it into a variable itself so i can create a link to that specific page on their site. So basically I need to know how to take the first letter from a string and store it in its own variable. Any help with this would be greatly appreciated, thanks,

ryan
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

substr() or simply use the array indexing to get the character.

Code: Select all

$a = 'Hello';
$b = $a[0];
$c = $a{0};
var_dump($a,$b,$c);
Post Reply