Jump to content

Recommended Posts

I need to find out how many lines are within a forum post upon my site (which is a custom-made forum). For example:

 

<?PHP

$string="Line 1.
Line 2.
Line 3.";

?>

 

Bad example, obviously, but anyway, that string has three lines... I need to count how many lines are within a string. So,

 

<?PHP

$string="bleh
moo
k
hi
spam";

?>

 

That string has five lines... so, if, for example, it was something that doesn't have an obvious amount of lines, like a forum post, I would need some sort of way to count how many lines are in that post.

based on your example.. this will be inpreted as 1 line only..

 

$string="bleh
moo
k
hi
spam";

 

unless you have "\n" inside the var..

 

 

Wrong.  The \n would be in the source file.

 

 

 

count(explode("\n", $str));

 

Will give you how many lines.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.