-1

I am writing a small application to compare text files and email the comparison. My code works on linux without errors, but when running it on wamp, I get a parse error at the last line of the file. Is there something I'm missing here?

<?php

ini_set('display_errors',1);  
error_reporting(E_ALL & ~E_NOTICE);

$myDate = date('mdy');
$todayfile = "s".$myDate.".txt";
$to      = 'myemail@gmail.com';
$myfile = fopen("output"."$myDate", "w");



$listings = file('listings.txt', FILE_IGNORE_NEW_LINES);
$solditems = file("$todayfile", FILE_IGNORE_NEW_LINES);


if (file_exists("$todayfile")) {
    foreach ($listings as $listing){
    $founditems = preg_grep("/$listing/", $solditems);
            foreach ($founditems as $founditem){
            echo nl2br("\n$founditem");
            fwrite($myfile, "$founditem" . "\r\n");
    }
        }
            }
    $body = file_get_contents("c:\drs\".$myfile); 
    mail($to, 'test', $body);

else {
echo 'Day not closed or no items found';
}


?> 

Any help would be greatly appreciated.

1 Answers1

3

You have a syntax error in this line

$body = file_get_contents("c:\drs\".$myfile); 

You need to escape the backslash with another backslash.

$body = file_get_contents("c:\drs\\".$myfile); 
Tristan
  • 3,301
  • 8
  • 22
  • 27
  • 1
    that or just not use backslashes for paths. php will translate `/` as appropriate for the host OS anyways. `c:/drs/` is valid on windows – Marc B Dec 14 '15 at 20:13