Tag Archives: textarea

PHP: Loop through each string line in a Textarea CodeUnit 08 FEB 2011

To loop through all the string inputs entered on a new line for a textarea control is not particularly challenging and uses basic array functionality to achieve this.

To see the code in action:

//trim off excess whitespace off the whole
$text = trim($_POST['textareaname']);

//explode all separate lines into an array
$textAr = explode("\n", $text);

//trim all lines contained in the array.
$textAr = array_filter($textAr, 'trim');

//loop through the lines
foreach($textAr as $line){
echo "$line";


jQuery Text Area Character Counter CodeUnit 20 MAR 2010

Aaron Russell has gone and created a huge time saving jQuery plugin for us all to use in the form of his nifty jQuery Simply Countable plugin which basically provides a character counter for any text input or textarea box.

Using it is as simple as going


but it comes packed with loads of extra settings which allow you to specify the actual counter jQuery selector, what to actually count, how many of that thing to count and whether or not we can allow people to exceed the limit for example.

It comes released under both the MIT and GPL licenses and it is hosted on  GitHub, the home of social coding.

The following is a screenshot of it in action:

Note the counter at the bottom left of the image. Obviously you could style this to whatever you want.

Thanks Russell, a great little plugin that saved me some valuable time creating the same functionality from scratch! :)

Related Link: http://github.com/aaronrussell/jquery-simply-countable