String

Discussion in 'PHP' started by Danago, Dec 6, 2006.

  1. #1
    Hey. Lets say i have a string...$string...

    How can i replace each individual letter of $string with the following:

    "Letter is [letter]"

    where [letter] is the corrosponding letter. I was thinking about putting each letter into an array and using a foreach loop, but i dont know how to split the string up :(

    Thanks in advance,
    Dan.
     
    Danago, Dec 6, 2006 IP
  2. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #2
    a string is automatically a array of letters so you can just do the following..

    
    $string="blah blah";
    $x=0;
    while ($string[$x]!="")
    {
       echo "$x: Letter is $string[$x]<br>";
       ++$x;
    }
    
    PHP:
     
    klown, Dec 6, 2006 IP
  3. Danago

    Danago Active Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for the help :) Exactly what im looking for :)
     
    Danago, Dec 6, 2006 IP