Solved

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

Posted on 2011-03-15
2
233 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now