php - check if there is something below the last line of a file -


i need check if there below last line. (if can place cursor below it, should match.)

this first line last line | 

note: | below this last line represents there empty line below last line, can place cursor below last line.

how can detect this? tried preg_match, solution linux commands fine.

https://regex101.com/r/my9wq3/2

here's solution regex:
it checks 2 consecutive eol @ end of text buffer, in possible variants.

code

<?php  // function ---------------------------------------------------------- function haseolatend($text) {     return (preg_match('/.*?(\r\n|\n\r|\r|\n){2,2}$/s', $text)); }  // -----------------------------------------------------------------------  // tests ----------------------------------------------------------------- $text_1 = "this 1 line - without eol"; $text_2 = "this 1 line - eol "; $text_3 = "these 2 lines -  without eol"; $text_4 = "these 2 lines -  eol ";  echo '$text_1 has ' . (haseolatend($text_1) ? 'eol' : 'no eol') . ' @ end<br />'; echo '$text_2 has ' . (haseolatend($text_2) ? 'eol' : 'no eol') . ' @ end<br />'; echo '$text_3 has ' . (haseolatend($text_3) ? 'eol' : 'no eol') . ' @ end<br />'; echo '$text_4 has ' . (haseolatend($text_4) ? 'eol' : 'no eol') . ' @ end<br />'; // ----------------------------------------------------------------------  ?> 

result

$text_1 has no eol @ end $text_2 has eol @ end $text_3 has no eol @ end $text_4 has eol @ end 

Comments