separate the string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    separate the string

    hello

    I am new to php and i want to separate the string "hello, everyone how are you?"

    and want to echo (print) all the characters separetly in php. how can i do that.
  • chinmay4u
    New Member
    • Dec 2007
    • 5

    #2
    Its very easy u should try urself to solve these kinds of methods any way here is the code ,


    <?php
    $someWords = "hello, everyone how are you?";
    $wordseparate = explode(" ", $someWords);
    for($i = 0; $i < count($wordsepa rate); $i++){
    echo "$wordsepar ate[$i] <br />";
    }
    ?>

    good luck , keep experimenting.

    Comment

    • mukeshrasm
      Contributor
      • Nov 2007
      • 254

      #3
      Originally posted by chinmay4u
      Its very easy u should try urself to solve these kinds of methods any way here is the code ,


      <?php
      $someWords = "hello, everyone how are you?";
      $wordseparate = explode(" ", $someWords);
      for($i = 0; $i < count($wordsepa rate); $i++){
      echo "$wordsepar ate[$i] <br />";
      }
      ?>

      good luck , keep experimenting.
      it prints
      Hello,
      everyone
      how
      are
      you?

      but i want all the character must nbe separated like
      H
      e
      l
      l
      o

      and so on.

      so please if you can help me!

      Comment

      • brettl
        New Member
        • Sep 2007
        • 41

        #4
        You can use str_split and create an array of all the characters.

        [CODE=php]
        <?php
        $someWords = "hello, everyone how are you?";
        $wordseparate = str_split($some Words);
        for($i = 0; $i < count($wordsepa rate); $i++){
        echo "$wordsepar ate[$i] <br />";
        }
        ?>
        [/CODE]

        I hope this helps.

        Comment

        Working...