tags:

views:

120

answers:

3

I have a textarea submitted to a php file.

Im using this to make it look exactly as the user entered the text:

 $ad_text=nl2br(wordwrap($_POST['annonsera_text'], 47, "\n", true));

If I want to resize a container I must be able to read how many lines are in the variable '$ad_text'.

Is there a way to do this...

I am still learning so thanks for your help...

A: 
$lines = explode($text, "\n");
$count = count($lines);
$html = implode($lines, "<br>");
just somebody
I don't think you need to do implode.
NawaMan
The $count only is '1', no matter what I put in the string ???
Camran
The parameters for explode() are backwards. Try explode("\n", $text);
GZipp
+2  A: 

You want the substr_count function.

Richard Levasseur
+1: A more direct answer than mine :-D
NawaMan
+1  A: 
NawaMan
This shows also '1', could it be that the nl2br adds a break instead of a new-line? how can I count the breaks as well
Camran
Please see my edit.
NawaMan
P E R F E C T! Thanks
Camran
nl2br() doesn't replace "\n"; it adds "<br />" right before it. If the line ending is "\r\n", the "<br />" is added before the "\r"; if there is only "\r" (but no "\n"), "<br />" is still added before it.
GZipp
@GZipp: Thanks for clearify. I have not used it for quite sometime.
NawaMan