Jump to content

Recommended Posts

Many thanks; I'm not too sure how to emplement this though...?

 

I've tried:

 

<?php
$input = $_POST['input'];
$count = 0;
$while = 0;


$split = explode("\n", $input);

while($while == 0) {

if ( $split[$count] == "" ) {

$while = 1 ;


} else {

// my action will go here
echo $count;
echo '                 -       ';
echo $split[$count];
echo '<br>';
//
$count = $count + 1;

}
}
?>

 

It's working, but coming up with:

Notice: Undefined offset: 2 in C:\wamp\www\splitfile.php on line 11

 

Any idea?

You can just use something like:

 

$input = $_POST['input'];
$split = explode("\n", $input);

foreach ($split as $line)
{
    if ($line != '')
    {
        echo $line . '<br />';
    }
}

 

You'll probably want to add a <br /> tag to the end otherwise they'll all be on the same line.

 

Edit: Just seen the <br> you had before!

I think you may be making it more complicated than it need be ...

 

<?php

$input = $_POST['input'];

$split = explode("\n", $input);

foreach ($split as $key => $value) {

     //DO ACTION ON THE INDIVIDUAL SPLIT INDEX
     echo $value . "<br />";

}

?>

I think you may be making it more complicated than it need be ...

 

<?php

$input = $_POST['input'];

$split = explode("\n", $input);

$key = 0;

$limit = count($split);

while($limit <= 0) {

     //DO ACTION ON THE INDIVIDUAL SPLIT INDEX
     echo $split[$key];

    //INCREMENT FOR THE NEXT ITERATION
    $key++;
}

?>

 

I think you are...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.