Page 1 of 1

Finding an empty line in an array

Posted: Sat Jan 14, 2006 3:15 am
by MarkAshley
I am trying to separate the header from the content in an emlx message. After the header is always a blank line, so I am trying to search for this within the message:

Code: Select all

$mailLines = file('/mail.emlx');
for ($i = 0; $i < count($mailLines); $i++) {
  if ($mailLines[$i] = "") {
    echo "First line of message<br>";
    $i++;
    echo "$mailLines[$i]<br>";
  }
}
However nothing is ever echoed so the if statement never evaluates true. What can I search for to find an empty line?

Thanks
Mark

Posted: Sat Jan 14, 2006 3:37 am
by JAM
Try array_search() ?
array_search -- Searches the array for a given value and returns the corresponding key if successful

Posted: Sat Jan 14, 2006 9:25 am
by duk
i dont understand if you want to find the empty line or to deal with empty lines...

but if the problem is dealing with empty lines in files... try a good combination with explode(); put every line in diferent arrays using explode("\n",$content); then will be possible and easy to find empty arrays...

ex: array[0] = "string"; array[1] = "";

anyway this examplo help you in both ways... find and deal with empty lines...

Posted: Sat Jan 14, 2006 9:39 am
by neophyte

Code: Select all

if ($mailLines[$i] = "\n") {
I think that might work...

Posted: Sat Jan 14, 2006 11:11 am
by Chris Corbyn
neophyte wrote:

Code: Select all

if ($mailLines[$i] = "\n") {
I think that might work...
== not = :) Of course it was a typo I'm just being a pedant :P

neophyte is right, the blank line is not actually a blank line, it simply contains nothing but a line break character ;)