Results 1 to 6 of 6

Thread: To read the specified character

  1. #1

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    To read the specified character

    hi,

    what is the PHP function to read the specified character -given its position in the string- in a string variable(just like Instr() function in VB)?

    thanks in advance
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  2. #2
    Lively Member Bolerophone's Avatar
    Join Date
    Dec 2003
    Location
    Himalayas
    Posts
    123

    Re: To read the specified character

    [code]

    $twister = "peter picked a peck of pickeled peppers";
    print(strpos($twister,"peck");
    // this will print the position of peck in the string $twister
    [code]

    HTH
    Jobs: "Do u want to sell colored sugar water or change the world?"

    Get Firefox Now!!!
    Mendhak leaving town.

  3. #3

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    Re: To read the specified character

    well that's not the one I'm looking for,but that's my fault, I wasn't clear enough. I want the function to read the character at the given position. The character is not known.

    e.g
    $string="What a beautiful day"
    echo functioniwant($string,2)
    ----------------------------------
    The result should be "h".
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: To read the specified character

    I think the function you want is substr()

    Or, you can just do this:

    String${Character_Number_Here}

    Both will return the character

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  5. #5

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    Re: To read the specified character

    thanks sciguyryan
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  6. #6
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: To read the specified character

    Quote Originally Posted by kill_bill_gates
    thanks sciguyryan

    You are welcome

    Just remmber if your thread has been solved edit the original post and add [Resolved] to its title and the green checkmark as its icon

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width