Grabbing first character of a variable help

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
banpro
Forum Newbie
Posts: 13
Joined: Tue Aug 05, 2003 4:21 pm

Grabbing first character of a variable help

Post by banpro »

Hi all,

I have a variable named $holder with a value of "Supreme", what I need to do is grab the first character and make it a variable named $grabbed, so $grabbed would then have a value of "S".

I thought I could do this using fgetc() or maybe fseek(), but I can't find a way to get them to work for me. I know they're intended for when reading from files but it seemed as though they should be usable with a string, but I guess not.

I'd really appreciate any ideas or suggestions on some other commands/functions that might work for doing something like this.

Thanks in advance,
Scott
Bongulim
Forum Newbie
Posts: 21
Joined: Thu Aug 07, 2003 12:50 pm

Post by Bongulim »

banpro
Forum Newbie
Posts: 13
Joined: Tue Aug 05, 2003 4:21 pm

Post by banpro »

Perfect, thanks,
Scott
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Code: Select all

<?php
$string = "String";
$grabbed = $string{0};
echo $grabbed;
?>
wheee!!!
Bongulim
Forum Newbie
Posts: 21
Joined: Thu Aug 07, 2003 12:50 pm

Post by Bongulim »

jason wrote:

Code: Select all

<?php
$string = "String";
$grabbed = $string{0};
echo $grabbed;
?>
wheee!!!
um... nice, didn't know of that.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Hehe, figured you didn't. Not everyone knows about it, but it's a nice feature, nonetheless.
Post Reply