Breaking that string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charanraj1191g
    New Member
    • Jul 2008
    • 9

    #1

    Breaking that string

    Can any one help me out.

    I have designed a form in which I have one text box and a submit button.
    User can type in a message which can be of variable length and include spaces.
    I want to break this string into INDIVIDUAL CHARACTERS And also I want to place a string before and after every character
    i.e

    suppose I have entered the text as 1234
    then I must get the output as
    I love 1 girl(s) I love 2 girl(s)
    and so on .can any one help me out !
  • Gulzor
    New Member
    • Jul 2008
    • 27

    #2
    something like that ?

    [php]
    <?php
    $str = $_POST['message'];
    $max = strlen($str);
    for ($i = 0; $i<$max; $i++) {
    echo 'prefix : ' . $str[$i] . '<br>';
    }
    ?>
    [/php]

    Comment

    • charanraj1191g
      New Member
      • Jul 2008
      • 9

      #3
      It is ok but now I'm getting only the first and the last (prefix & suffix)
      the main thing i.e the INDIVIDUAL CHARACTER OF THE STRING IS MISSING

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by charanraj1191g
        It is ok but now I'm getting only the first and the last (prefix & suffix)
        the main thing i.e the INDIVIDUAL CHARACTER OF THE STRING IS MISSING
        Post the code you used.

        Comment

        • charanraj1191g
          New Member
          • Jul 2008
          • 9

          #5
          I used this
          [code=php]
          <?php
          $str=$_POST['word'];

          echo 'i love' .chunk_split($s tr,1,'girl(s)'
          ?>
          [/code]
          i get the out put as i love1234girl(s)

          i want the prefix and the suffix to be appeared after every character i.e
          1 2 etc
          Last edited by Atli; Jul 24 '08, 12:19 AM. Reason: Added [code] tags

          Comment

          • charanraj1191g
            New Member
            • Jul 2008
            • 9

            #6
            Originally posted by r035198x
            Post the code you used.
            [code=php]
            <?php
            $str=$_POST['word'];

            echo 'i love' .chunk_split($s tr,1,'girl(s)'
            ?>
            [/code]
            i get the output as i love1234girl(s)
            but i want it to be i love 1 girl(s) ...and so on
            Last edited by Atli; Jul 24 '08, 12:20 AM. Reason: Added [code] tags

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by charanraj1191g
              I used this
              <?php
              $str=$_POST['word'];

              echo 'i love' .chunk_split($s tr,1,'girl(s)'
              ?>
              i get the out put as i love1234girl(s)

              i want the prefix and the suffix to be appeared after every character i.e
              1 2 etc
              You certainly need a loop then. Use the method suggested in the first response in this thread.

              Comment

              • charanraj1191g
                New Member
                • Jul 2008
                • 9

                #8
                Originally posted by r035198x
                You certainly need a loop then. Use the method suggested in the first response in this thread.
                Can you please tell me how to I am a new to this!!!!!!!!!!! !!!
                Please help me!!

                Comment

                • charanraj1191g
                  New Member
                  • Jul 2008
                  • 9

                  #9
                  Originally posted by r035198x
                  You certainly need a loop then. Use the method suggested in the first response in this thread.
                  If possibe can you tell me the code for this ?

                  Comment

                  • charanraj1191g
                    New Member
                    • Jul 2008
                    • 9

                    #10
                    Originally posted by charanraj1191g
                    If possibe can you tell me the code for this ?
                    AAAAAAAAAAAAAAA AAA!!!!!!!!!!!! !!!!!!!
                    THANKS !!!!!!
                    I Got it !!!!!!!!!!!!!!! !!!!!!!!!!!!!!!

                    Comment

                    • charanraj1191g
                      New Member
                      • Jul 2008
                      • 9

                      #11
                      Originally posted by Gulzor
                      something like that ?

                      [php]
                      <?php
                      $str = $_POST['message'];
                      $max = strlen($str);
                      for ($i = 0; $i<$max; $i++) {
                      echo 'prefix : ' . $str[$i] . '<br>';
                      }
                      ?>
                      [/php]
                      Sorry Friend I made a mistake in the code Your Code Works Thanks A lot!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!
                      Woooooooooooooo oooo!!!!

                      Comment

                      • Atli
                        Recognized Expert Expert
                        • Nov 2006
                        • 5062

                        #12
                        Am I the only one that feels like the OP is in fact two people using the same account? :P

                        Anyhow, please use [code] tags when posting code examples.
                        Thanks.

                        Comment

                        • charanraj1191g
                          New Member
                          • Jul 2008
                          • 9

                          #13
                          Originally posted by Gulzor
                          something like that ?

                          [php]
                          <?php
                          $str = $_POST['message'];
                          $max = strlen($str);
                          for ($i = 0; $i<$max; $i++) {
                          echo 'prefix : ' . $str[$i] . '<br>';
                          }
                          ?>
                          [/php]
                          how can I replace the space in the script with _ sign?
                          And one more question is it possible to make tables that can be dragged to any position in the browser ?

                          Comment

                          Working...