How could I get the number of lines, from a LONGTEXT
String that we retrieved from a MySQL database, using HTML, or PHP? For example, Let's say I have this text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam imperdiet condimentum libero at eleifend. Mauris ac justo in purus tempor iaculis vitae at turpis. Cras quis facilisis libero. Nam molestie neque id lacus cursus rutrum. Aliquam vestibulum blandit diam, a placerat
I would like to be able to find out how many lines, or how much "room" the text takes up.
It is one line, yet, it appears as 3 lines, so, I would like to get 3
, by doing something like $num = count_lines($string);
using PHP, or something more complicated than that.
This is for formatting a forums website that I'm making, changing certain aspects dynamically based on how much room the text takes up
I've tried things like:
<?php
$num = substr_count($string, "\n");
?>
and
<?php
$num = count(preg_split('/\n|\r/',$str));
?>
But they don't work because I'm getting the string out of a MySQL database.
Also, I would like the number to change based on the margin. As you can see, the number of lines in:
jsfiddle.net/n58z74pg is different from the number of lines in jsfiddle.net/6nkvLzzn because the text has a style of margin-right:10cm
.
So, is there any way to get the number of lines in a string using only HTML, or PHP? Maybe by counting the number of pixels that the text takes up, then doing some basic math to find out the number of lines?