Forum Moderators: coopster

Message Too Old, No Replies

finding line break

         

gchristen

12:26 am on Feb 24, 2010 (gmt 0)

10+ Year Member



Hi there.

I would like my PHP script to find line breaks in a txtfile/string and only consider the text after the first line break.

Example 1 text file:

red
blue

green
yellow


The script would output:

green
yellow


Example 2 text file:

red
blue

green
yellow

violet
magenta



The script would output:

green
yellow

violet
magenta


any advice?

many thanks!

edacsac

1:47 am on Feb 24, 2010 (gmt 0)

10+ Year Member



Here are a couple of options to get you started based on your examples, but by no means the best or most elegant.


$str="red
blue

green
yellow";

/**** option 1 ****/

$br=strpos($str, "\n\n");
$len=strlen($str)-$br;
$newStr=substr($str, $br, $len);

echo "newStr1: ".$newStr;

/**** option 2 ****/

$strArr=explode("\n\n", $str);
$len=sizeof($strArr);

for($i=1;$i<$len;$i++){
$newStr2.=$strArr[$i];
}

echo "<br><br>newStr2: ".$newStr2;

penders

2:37 pm on Feb 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would like my PHP script to find line breaks in a txtfile/string and only consider the text after the first line break.


We know what you mean from your example, but I think you mean blank line? There is a line break at the end of every line.

gchristen

1:57 pm on Feb 25, 2010 (gmt 0)

10+ Year Member



I'll give your example a try, thanks!

(and yes indeed, I mean blank line, not line break)

Cheers everyone