Connecting Tech Pros Worldwide Forums | Help | Site Map

how do you pull specific characters in from a $string

revjjjames@hotmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
Good evening,

I want to create a method that will tell me the 10th and 11th character
in a string, and store it as $something. How can this be done?

Sincerely,

J


Jan Pieter Kunst
Guest
 
Posts: n/a
#2: Jul 17 '05

re: how do you pull specific characters in from a $string


revjjjames@hotmail.com wrote:[color=blue]
> Good evening,
>
> I want to create a method that will tell me the 10th and 11th character
> in a string, and store it as $something. How can this be done?[/color]

One possibility:

$string = 'abcdefghijklmnopqrstuvwxyz';
$something = $string{9} . $string{10};

echo $something;

outputs: jk

Other ways could involve substr() and other string functions, but the
above was the first that came up.

JP

--
Sorry, <devnull@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Daniel Tryba
Guest
 
Posts: n/a
#3: Jul 17 '05

re: how do you pull specific characters in from a $string


In comp.lang.php revjjjames@hotmail.com wrote:[color=blue]
> I want to create a method that will tell me the 10th and 11th character
> in a string, and store it as $something. How can this be done?[/color]

You do know about the manual, do you? Search for "Return part of a
string" on http://www.php.net/manual/en/ref.strings.php

If you need "String access and modification by character" look at that
chapter on http://www.php.net/manual/en/language.types.string.php

Chris Hope
Guest
 
Posts: n/a
#4: Jul 17 '05

re: how do you pull specific characters in from a $string


revjjjames@hotmail.com wrote:
[color=blue]
> I want to create a method that will tell me the 10th and 11th
> character
> in a string, and store it as $something. How can this be done?[/color]

http://www.php.net/substr

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Closed Thread