Connecting Tech Pros Worldwide Help | Site Map

how do you pull specific characters in from a $string

  #1  
Old July 17th, 2005, 01:15 PM
revjjjames@hotmail.com
Guest
 
Posts: n/a
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

  #2  
Old July 17th, 2005, 01:15 PM
Jan Pieter Kunst
Guest
 
Posts: n/a

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.
  #3  
Old July 17th, 2005, 01:15 PM
Daniel Tryba
Guest
 
Posts: n/a

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

  #4  
Old July 17th, 2005, 01:15 PM
Chris Hope
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Requesting advice how to clean up C code for validating string represents integer robert maas, see http://tinyurl.com/uh3t answers 232 April 16th, 2007 04:55 AM
Storage of char in 64 bit machine aruna.mysore@gmail.com answers 74 August 28th, 2006 06:25 AM
Strings in VB.Net cjobes answers 3 November 21st, 2005 07:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM