ionis Posted February 15, 2011 Share Posted February 15, 2011 Hey guy, I really need your help with this. I have Input from a text area, in this format: a b c d e f g 12 34 435 124 What I need do to is to output only a certain line from every block of text, every block is divided by one or more empty lines. I have done this: $input = $_POST["input"]; $lines = explode("\r",$input); $num = count($lines); $line_to_extract = $_POST['line_to_extract']; for($i=0;$i<$num;$i++) { if($i == $line_to_extract) { echo 'Line '.$i.': '.$lines[$i].'<br />'; } } What I need to do is to detect the empty line so I can keep track of the line to extract. PLEASE HELP!!! Link to comment https://forums.phpfreaks.com/topic/227737-help-detecting-empty-lines-in-a-text-area/ Share on other sites More sharing options...
ronverdonk Posted February 16, 2011 Share Posted February 16, 2011 Use 2 counters: $i for the entire array and $j for the line no within a block, as follows: for($i=0,$j=1; $i<$num; $i++,$j++) { if (strlen(trim($lines[$i])) == 0) { $j=0; continue; } if($j == $line_to_extract) { echo 'Line '.$i.': '.$lines[$i].'<br />'; } } Ronald Link to comment https://forums.phpfreaks.com/topic/227737-help-detecting-empty-lines-in-a-text-area/#findComment-1175353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.