3

I checked my code using php codesniffer and got this error:

enter image description here

It says the error happened in the first line of the code, but all I have in the first line of my code is a php opening tag:

<?php

Is there a program to show these characters and fix it? I also tried phpcbf command but it doesn't appear to work:

enter image description here

NL500
  • 1,165
  • 2
  • 9
  • 13

2 Answers2

0

I assume you are using windows. Your file uses unix lineendings ("\n") Windows uses ("\r\n")

you could convert the lineendings in the commandline with

type input_filename | more /P > output_filename

or open your sourcefiles with an editor like notepad++ and change lineendings to windows

lumos0815
  • 3,908
  • 2
  • 25
  • 25
  • Thanks the command didn't work work for me, but notepadd++ did: http://stackoverflow.com/questions/11341660/change-eol-on-multiple-files-in-one-go – NL500 Oct 07 '15 at 13:46
0

PHP codesniffer should be checking against the default EOL of the OS it is running on, so EOL will be \n for Linux and \r\n for Windows.

Most likely, what has happened is that one of the files you are checking has the wrong or mixed EOL for the current OS (this is what happened to me). This might not be obvious as file editors often compensate for this.

Many editors, though, do have a feature to tell you what the EOL of the file is, or even to reset it. Notepad++ on Windows has this from the Edit menu. On linux, use the file command to detect, and use dos2unix or unix2dos, as needed.

James John McGuire 'Jahmic'
  • 11,728
  • 11
  • 67
  • 78