Solved

How do you know how many lines in a post string?

Posted on 2011-03-15
2
250 Views
Last Modified: 2012-06-21
when I post from a textarea, I'd like to know how many lines they are, so I can then begin a for() loop, how do I do a for loop?
0
Comment
Question by:eNarc
2 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 250 total points
ID: 35137701
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 35137718
"lines" in a textarea are normally defined by "\n" characters so you could count them like so

$lines = explode( "\n", $_POST['textAreaName'] );

echo "The number of lines is " . count( $lines );


and process them by

foreach( $lines as $aLine ) {

     // As a demo just echo each line out and put a BR after it
     //
     echo "$aLine<br/>";

}
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question