473,383 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to count lines from a form?


I'm having trouble working this out ...

Is there a simple way to count how many lines are returned in
$_POST['myTextArea']

When I look at the $_POST all I see is one line yet there are three.
I assume something is being interpreted differently depending on how I
view it.

Is there a simple funtion for this or can someone tell me how to work it
out please?

Thanks

andy
Mar 12 '07 #1
4 2432
On Mar 12, 5:58 am, and...@blueyonder.com wrote:
I'm having trouble working this out ...

Is there a simple way to count how many lines are returned in
$_POST['myTextArea']

When I look at the $_POST all I see is one line yet there are three.
I assume something is being interpreted differently depending on how I
view it.

Is there a simple funtion for this or can someone tell me how to work it
out please?

Thanks

andy

Hey,

This should do the trick,

$lineCount = count( explode( "\n" , $_POST['test'] ) );

where 'test' is the nameof the textarea field

Mar 12 '07 #2
an****@blueyonder.com wrote:
I'm having trouble working this out ...

Is there a simple way to count how many lines are returned in
$_POST['myTextArea']

When I look at the $_POST all I see is one line yet there are three.
I assume something is being interpreted differently depending on how I
view it.

Is there a simple funtion for this or can someone tell me how to work it
out please?
Do you reallly have three lines in your textarea, that it three bits of text
seperated by \n (the enter key)? Or, is your textarea simply word-wrapping
the text onto three "visible" lines?

--
Richard.
Mar 12 '07 #3
In article <11*********************@s48g2000cws.googlegroups. com>,
jo********@gmail.com says...
On Mar 12, 5:58 am, and...@blueyonder.com wrote:
I'm having trouble working this out ...

Is there a simple way to count how many lines are returned in
$_POST['myTextArea']

When I look at the $_POST all I see is one line yet there are three.
I assume something is being interpreted differently depending on how I
view it.

Is there a simple funtion for this or can someone tell me how to work it
out please?

Thanks

andy


Hey,

This should do the trick,

$lineCount = count( explode( "\n" , $_POST['test'] ) );

where 'test' is the nameof the textarea field

clever!
Thanks - that makes sense now I've seen it ;-)
I'll give it a go.

cheers

andy
Mar 12 '07 #4
Tom
On Mar 12, 8:25 am, and...@blueyonder.com wrote:
In article <1173696650.014897.36...@s48g2000cws.googlegroups. com>,
jon.pul...@gmail.com says...


On Mar 12, 5:58 am, and...@blueyonder.com wrote:
I'm having trouble working this out ...
Is there a simple way to count how many lines are returned in
$_POST['myTextArea']
When I look at the $_POST all I see is one line yet there are three.
I assume something is being interpreted differently depending on how I
view it.
Is there a simple funtion for this or can someone tell me how to work it
out please?
Thanks
andy
Hey,
This should do the trick,
$lineCount = count( explode( "\n" , $_POST['test'] ) );
where 'test' is the nameof the textarea field

clever!
Thanks - that makes sense now I've seen it ;-)
I'll give it a go.

cheers

andy- Hide quoted text -

- Show quoted text -
If you want to be precise, you should `trim` your result first to
check to see if any value was passed. `explode` will always return an
array of length 1, even if the string parameter is empty (or even
NULL):

<?php
$string = "Hello world" ;
echo count( explode( "\n" , $string ) ) ; // "1"
$string = "" ;
echo count( explode( "\n" , $string ) ) ; // "1", not sure if that's
what you need or not
?>

`trim` will also get rid of newlines at the end of a string -- I've
noticed that on Safari in particular, textareas seem to add newlines
regardless of where "Enter" or "Return" was hit.

Mar 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve Gdula | last post by:
Can anyone recommend a good way to get the count of the 'Number of Lines of Code' that are part of a vbProject. This should include all class and standard modules as well as the forms. If I can be...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
5
by: Mike Bannon | last post by:
Hi All We have an order processing database which includes the standard Order Header/Order Lines tables. I'm trying to write a query to get the average number of lines per order over a given...
2
by: Andy | last post by:
I need to be able to count the number people who are registered in a certain IT course. i need to display the results on a form or report. This is for my A level courswork please help! thanks
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
23
by: Paul Mars | last post by:
I need to limit multiline textbox to 3 lines of text and if there are less then 3 lines when leaving, add empty line holders. How can I do this?? Thanks, paul
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
3
by: waynejr25 | last post by:
can anyone help me add a function that will count the occurance of each word in an input file. here's the code i have so far it counts the number of characters, words, and lines but i need the...
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.