How to use data line by line in for loop.

Actually I want to get data form form (text area).

And use it line by line. (usual line ends when user hits enter while typing)

Usage Example:
for(line number less then < and ++ function)
{
Statements/using data
}

Now how I can separate “text area” data into lines and use every line count wise. Please help.

You can’t do it that way.

First, a text area is text. It is basically a string. You can lot it into a variable.
Then, use the variable to parse thru looking for line breaks. ("\n")

Another way is to break it down into an array using line breaks. To do this, you basically use the array or list commands. Here is an example of such:
$TotalText = $_POST[‘TextAreaName’];
$LinesArray = explode("\n", $TotalText);

This creates an array that is separate lines of the textarea data.
You can then loop thru the array with $LinesArray[1], $LinesArray[2] etc… and handle your data…

Hope that helps!

Ok I understand but how to use $LinesArray[1], $LinesArray[2]… using loop??

I do something I dont know it blocks my web :’(

Please so a some help more. Thanks.

Well, the first step would be to learn more PHP. You can do that at www.php.net. Or any other php site.

In general, you should look at your data and understand that first. So, if you have a text area called, let’s say “textarea1”, then, to look at this in a string variable, you would use something like:
$textdata = textarea1.value;
This would load the text inside the textarea into the variable $textdata.
Once you have that, you would be able to display this data. Such as: echo $textdata;
That command will display your REAL data text that is inside of the textarea where someone has typed.
You should start there and type in some multiple lined text and display it and see how it is really formatted. Next, you can use the explode command to create an array of the lines based on the carriage returns that are put into the textarea. Then, learn how to sort thru them line by line…
Hope that helps…

Look at this for Implode info: http://php.net/manual/en/function.implode.php

Sponsor our Newsletter | Privacy Policy | Terms of Service