explode() Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maximus

    explode() Function

    <?php
    $numbers=$_POST['numbers'];

    if(!$_POST['Submit']) { ?>
    <form name="form1" method="post" action="">
    <p>
    <textarea name="numbers" cols="100" rows="15"
    id="numbers"></textarea>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    <?
    } else {
    //$replaced=preg_ replace("/\n$/", ',', $numbers);
    $exploded=explo de('\n', $numbers);
    ?>
    <form name="form1" method="post" action="">
    <p>
    <textarea name="numbers" cols="100" rows="15" id="numbers">< ? echo
    $exploded[0], $exploded[1]; ?></textarea>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    <? } ?>

    ----------------------------------------------

    I have this code, I need to insert some numbers in the textbox

    for example:

    585284
    582084
    585209
    964587

    and so on, then i want them to be exploded and echoed back separated by
    commas. How can i exploded then into an array separated by new line?

  • Ivan Omelchenko 608308824

    #2
    Re: explode() Function

    Maximus пишет:[color=blue]
    > <?php[/color]
    skipped[color=blue]
    > ----------------------------------------------
    >
    > I have this code, I need to insert some numbers in the textbox
    >
    > for example:
    >
    > 585284
    > 582084
    > 585209
    > 964587
    >
    > and so on, then i want them to be exploded and echoed back separated by
    > commas. How can i exploded then into an array separated by new line?
    >[/color]

    split ?
    Split string into array by regular expression (PHP 3, PHP 4 , PHP 5)
    array split ( string pattern, string string [, int limit] )

    Comment

    • Maximus

      #3
      Re: explode() Function

      i need the key code for ENTER.
      i can explode but i need to know what to put as a delimeter.

      what is the enter key in the delimeter.

      Comment

      • Ken Robinson

        #4
        Re: explode() Function

        Maximus wrote:[color=blue]
        > <?php
        > $numbers=$_POST['numbers'];
        >
        > if(!$_POST['Submit']) { ?>
        > <form name="form1" method="post" action="">
        > <p>
        > <textarea name="numbers" cols="100" rows="15"
        > id="numbers"></textarea>
        > </p>
        > <p>
        > <input type="submit" name="Submit" value="Submit">
        > </p>
        > </form>
        > <?
        > } else {
        > //$replaced=preg_ replace("/\n$/", ',', $numbers);
        > $exploded=explo de('\n', $numbers);
        > ?>
        > <form name="form1" method="post" action="">
        > <p>
        > <textarea name="numbers" cols="100" rows="15" id="numbers">< ? echo
        > $exploded[0], $exploded[1]; ?></textarea>
        > </p>
        > <p>
        > <input type="submit" name="Submit" value="Submit">
        > </p>
        > </form>
        > <? } ?>
        >
        > ----------------------------------------------
        >
        > I have this code, I need to insert some numbers in the textbox
        >
        > for example:
        >
        > 585284
        > 582084
        > 585209
        > 964587
        >
        > and so on, then i want them to be exploded and echoed back separated by
        > commas. How can i exploded then into an array separated by new line?[/color]

        Your code seems overly complicated. Try:

        <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']
        ?>">
        <p>
        <textarea name="numbers" cols="100" rows="15" id="numbers">
        <? if(isset($_POST['Submit']))
        echo implode(', ',explode("\n", $_POST['numbers'])); ?></textarea>
        </p>
        <p>
        <input type="submit" name="Submit" value="Submit">
        </p>
        </form>

        Ken

        Comment

        • Ivan Omelchenko 608308824

          #5
          Re: explode() Function

          Maximus пишет:[color=blue]
          > i need the key code for ENTER.
          > i can explode but i need to know what to put as a delimeter.
          >
          > what is the enter key in the delimeter.
          >[/color]
          Under Windows it's \r\n
          Under Unix OS it's only \n
          Just trim($textarea, "\r") then split using \n

          Comment

          Working...