how do you pull specific characters in from a $string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • revjjjames@hotmail.com

    #1

    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

  • Jan Pieter Kunst

    #2
    Re: how do you pull specific characters in from a $string

    revjjjames@hotm ail.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 = 'abcdefghijklmn opqrstuvwxyz';
    $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.

    Comment

    • Daniel Tryba

      #3
      Re: how do you pull specific characters in from a $string

      In comp.lang.php revjjjames@hotm ail.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

      Comment

      • Chris Hope

        #4
        Re: how do you pull specific characters in from a $string

        revjjjames@hotm ail.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]



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

        Comment

        Working...