Results 1 to 5 of 5

Thread: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

  1. #1

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

    So?

    I know there is a way but I just can igure out how to do this...
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  2. #2
    Hyperactive Member ..:RUDI:..'s Avatar
    Join Date
    Aug 2005
    Location
    Yorkshire, England! c0d: Da Vinci
    Posts
    344

    Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

    PHP Code:
    $var "string";
    $arr str_split($var); 
    Hope this helps



    My Personal Home | MageBB Home | Elders Online
    Yes, Noteme is my father.

  3. #3

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

    yes thank you, it helped, but this is new to PHP5, and I've been using php for a while and I'm sure there was another trick.. but anyway, thanks

    since I am still working with php4, I figured out a function myself
    PHP Code:
    function str_split($var)
    {
        
    $array = array();
        for(
    $i 0$i strlen($var); $i++){
            
    $array[] = substr($var$i1);
        }
        return 
    $array;

    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

    What do you need this for?

    You can use a string as an array, if you want.

    PHP Code:
    $var "string";
    echo 
    $var[3]; 

  5. #5
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: How to convert $var = "string" to $arr = ("s", "t", "r", "i", "n", "g")

    Or you could use explode:

    PHP Code:
    $var "string";
    $var explode($var""); 
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


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