PHP return charicter in 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
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

PHP return charicter in a string...

Post by siefkencp »

It's a silly question... sorry.

Ok, How's it done?... I know the position of the string I want to return (but not the value), how do i get it out?

Chris
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Say you want the letter 'a' in 'car'

Code: Select all

$myVar = 'car';

echo $myVar{1};
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

I tried it

Code: Select all

$var = "some value";
$pointer = 3;
$value = $var{$pointer};
print $value;
I get...
Parse error: syntax error, unexpected '{'
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

also take a look at substr().

it's not as elegant, but is a nice tool to have in your bag...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

siefkencp wrote:I tried it

Code: Select all

$var = "some value";
$pointer = 3;
$value = $var{$pointer};
print $value;
I get...
Parse error: syntax error, unexpected '{'

Works for me :?
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

I forgot a "$" ......

geez... every compiler/interpreter is a critic ...


Thanks guys!
Post Reply