Connecting Tech Pros Worldwide Help | Site Map

how do you pull specific characters in from a $string

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:15 PM
revjjjames@hotmail.com
Guest
 
Posts: n/a
Default how do you pull specific characters in from a $string

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, 12:15 PM
Jan Pieter Kunst
Guest
 
Posts: n/a
Default 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, 12:15 PM
Daniel Tryba
Guest
 
Posts: n/a
Default 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, 12:15 PM
Chris Hope
Guest
 
Posts: n/a
Default 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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.