Hello,
is there any way to count rows with php ?
Suppose I have ...
row row row row row row
Is there anything with php to return the result of 6 after analyzing the section above (3 rows).
Thank you.
Are you using MySQL to retrieve the rows from a database ? or just read the rows from a file ? 😕
Indeed; what are "rows"?
No , not from a database , I know I how to do from a database .
It should examine a part of html text and to show how many rows ...
Originally posted by Weedpacket Indeed; what are "rows"?
I extract from a html page these (rows ) ;
my house is red my car is blu radio head music radio
It should report 4 , because the text contains 4 rows.
Is it possible ?
Still not clear. Is this a string? An array? Or what?
Originally posted by Weedpacket Still not clear. Is this a string? An array? Or what?
the extracted html is on a string .
Is this a MySQL database? From the PHP manual:
$link = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $link); $result = mysql_query("SELECT * FROM table1", $link); $num_rows = mysql_num_rows($result);
Originally posted by graziano the extracted html is on a string .
And you want the number of lines.
Count the number of times \n appears in the string (using substr_count). If the last character in the string is \n, you might want to subtract 1 from the count (if you don't want to count the zero-length line right at the end).
Originally posted by Weedpacket And you want the number of lines. Count the number of times \n appears in the string (using substr_count). If the last character in the string is \n, you might want to subtract 1 from the count (if you don't want to count the zero-length line right at the end).
It should be a good idea , thank you very much (I will have to count <pre> however ).