title: Forcing fwrite to use \n instead of \r\n in PHP
body: <p>I'm running PHP on a Linux server and I'm generating bash scripts for use on a Mac computer with PHP's fopen/fwrite. It's working fine except the line endings are being written as \r\n instead of just \n, which causes error when I try to run the script on the Mac.</p>
  
  <p>How can I force fwrite to use \n instead of \r\n for line endings? I've tried utf8_encoding my text and forcing binary mode but I can't seem to figure it out!</p>
  
  <pre><code>   $scriptFile = "/path/to/my/script.sh";
     $fh = fopen($scriptFile, 'w');
     fwrite($fh, "$script");
     fclose($fh);
  </code></pre>
  
  <p>$script is the content from a text field in mysql, and looks a bit like this, typically:</p>
  
  <pre><code>   # comment
     echo "numphotos 1"
  
     # comment
     /opt/local/bin/gphoto2 --capture-image-and-download -F 1 
  
     # comment
     echo "696969"
  </code></pre>