Page 1 of 1

Grabbing first character of a variable help

Posted: Mon Aug 18, 2003 6:35 pm
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

Posted: Mon Aug 18, 2003 7:13 pm
by Bongulim

Posted: Mon Aug 18, 2003 7:22 pm
by banpro
Perfect, thanks,
Scott

Posted: Mon Aug 18, 2003 7:48 pm
by jason

Code: Select all

<?php
$string = "String";
$grabbed = $string{0};
echo $grabbed;
?>
wheee!!!

Posted: Mon Aug 18, 2003 8:01 pm
by Bongulim
jason wrote:

Code: Select all

<?php
$string = "String";
$grabbed = $string{0};
echo $grabbed;
?>
wheee!!!
um... nice, didn't know of that.

Posted: Mon Aug 18, 2003 9:32 pm
by jason
Hehe, figured you didn't. Not everyone knows about it, but it's a nice feature, nonetheless.