^M in vi with php files

Why do I see ^M in vi with php files? I don't see that in any other type of files.

I added this to my .bashrc and it went away. Does anyone know why this is happening? What does exporting xterm-color do that makes it go away?

export TERM="xterm-color"

Did you ever edit them in Notepad? That will fill them with carriage returns because Windows uses \r\n while UNIX uses \n

For PHP files or webpages it may not make an enormous difference. For other script files it can be an annoying problem.

I didn't. Someone else may have. I am learning me way around a new server right now. Trying to understand all of the shellscripts and php files.

In vi you can do

:%s/<C-V><C-M>//g

where C-V and C-M are keys you should press on keyboard.

This is happening because the file is imported from a Windows file system. Issue the command:

dos2unix filename.php

..to change the file to unix format.

...except nobody actually has dos2unix, so sed -i 's/\r//' filename will work better (on linux. on other systems you may need to tr -d '\r' < filename > tempname ; cat tempname > filename ; rm tempname )

What does this do? Does C-V mean ctrl V?

I don't have dos2inix but it is in my repository?

What do those sed and tr commands do? I like to learn :).

The issue here is to delete any \r char in the file, since windows uses \r\n and unix only accepts \n, the sed/tr/vi commands tries to acomplish the same effect on the file, to delete the \r char which is presented as a terminator on each line.

Hi.

If you use editor vim, you may be interested in fileformat. Here's a help excerpt:

                                        *'fileformat'* *'ff'*
'fileformat' 'ff'       string (MS-DOS, MS-Windows, OS/2 default: "dos",
                                Unix default: "unix",
                                Macintosh default: "mac")
                        local to buffer
                        {not in Vi}
        This gives the <EOL> of the current buffer, which is used for
        reading/writing the buffer from/to a file:
            dos     <CR> <NL>
            unix    <NL>
            mac     <CR>
        When "dos" is used, CTRL-Z at the end of a file is ignored.
        See |file-formats| and |file-read|.
...

Briefly, one uses:

:set fileformat=xxx

where xxx is one of unix, dos, mac

Best wishes ... cheers, drl