SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot forum11's Avatar
    Join Date
    Feb 2006
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String to Character Array

    How can I break an string to a an array of characters.
    e.g;
    $str = "123456";
    then after breaking above string, character array would be
    $arr = array('1','2','3','4','5','6');
    Do Good Have Good!

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    str_split (see comments there about php4 compatibility).

  3. #3
    SitePoint Zealot forum11's Avatar
    Join Date
    Feb 2006
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But I am using PHP Version: 4.4.2
    Do Good Have Good!

  4. #4
    SitePoint Zealot forum11's Avatar
    Join Date
    Feb 2006
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx I got it
    Do Good Have Good!

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For php4 just do this which is in php manual:
    PHP Code:
    $str 'two words';
    $array explode("\r\n"chunk_split($str,1));
    print
    "<pre>";
    print_r($array); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    To show there is more then one way.
    PHP Code:
    <?php

    preg_match_all
    ('/(\w)/''abcdefghijklmnopqrstuvwzyz'$regs);
    print_r($regs[0]);
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

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