Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

911 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

22 Experts available now in Live!

Get 1:1 Help Now