Finding an empty line in an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MarkAshley
Forum Commoner
Posts: 34
Joined: Fri Nov 18, 2005 1:36 am

Finding an empty line in an array

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Try array_search() ?
array_search -- Searches the array for a given value and returns the corresponding key if successful
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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...
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Code: Select all

if ($mailLines[$i] = "\n") {
I think that might work...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
Post Reply