^M in vi with php files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ^M in vi with php files
# 1  
Old 06-10-2011
^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?
Code:
export TERM="xterm-color"

# 2  
Old 06-10-2011
Quote:
Originally Posted by COKEDUDE
Why do I see ^M in vi with php files? I don't see that in any other type of files.
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.
# 3  
Old 06-10-2011
Quote:
Originally Posted by Corona688
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.
# 4  
Old 06-11-2011
In vi you can do
Code:
:%s/<C-V><C-M>//g

where C-V and C-M are keys you should press on keyboard.
# 5  
Old 06-11-2011
This is happening because the file is imported from a Windows file system. Issue the command:
Code:
dos2unix filename.php

..to change the file to unix format.
# 6  
Old 06-11-2011
...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 )
# 7  
Old 06-11-2011
Quote:
Originally Posted by yazu
In vi you can do
Code:
:%s/<C-V><C-M>//g

where C-V and C-M are keys you should press on keyboard.
What does this do? Does C-V mean ctrl V?

Quote:
Originally Posted by Corona688
...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 )
I don't have dos2inix but it is in my repository?

What do those sed and tr commands do? I like to learn Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Uploading files via php

I used the following code, which I found on the internet to upload files. <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="upload2.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input... (2 Replies)
Discussion started by: jgt
2 Replies

2. UNIX for Dummies Questions & Answers

Deleting from .php files

Hello, I have infected .php files on my server with some code (example at the bottom,code marked red must be deleted, all .php files were infected with this same code). I was wondering how can i delete the first <?php ?> with that all code inside ?:confused: I already tried with : find . -name... (20 Replies)
Discussion started by: Corlex31
20 Replies

3. Shell Programming and Scripting

Extract function names and directories from php files

I need a script that extracts function names from php files together with their location (path and file in which they are defined). The php files are located in several directories under a base directory. Ideally the output should be something like: "Path/FileName/FunctionName" for a... (2 Replies)
Discussion started by: bamse
2 Replies

4. Shell Programming and Scripting

finding php, html, htm files

how can i limit the output to only php, html, htm files? i found this as one way find . -regex ".*\(php\|html\|htm\)$" -type f -print0 | xargs -0 grep 'keyword'and it works but is a bit slow is there any faster way? i tried something like this but it doesnt work: find ./ -iname "*.php"... (2 Replies)
Discussion started by: vanessafan99
2 Replies

5. Shell Programming and Scripting

PHP Script Help - Making links to files Clickable

Ok so I wrote a php script that outputs the below to users on a webpage. # Download: /home/content/d/i/v/divine1234/eBookDownloads/ScalpRemedy_jablaa12734.zip the php code that outputs the above is: echo ("<li>Download: $download_link</li>\n"); The thing is, I dont want... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. UNIX for Dummies Questions & Answers

Find php files within any matching directory name?

I am trying to search my linux box for any PHP files located within ANY directory matching a certain name. So far nothing I've tried (nor any idea I've searched for) has worked as expected. I have tried a combination of find and grep...fail. Please help? (4 Replies)
Discussion started by: macwise7
4 Replies

7. Web Development

php files are downloaded

Hello, I have setup Cherokee web server and php 5.2 in Opensolaris zone. Problem is that all .php files are downloaded from web server and not served when I use IP address instead of DNS name in web brovser. Example: test.mydomain.com <-- php works 192.168.0.10/index.php <--... (3 Replies)
Discussion started by: kreno
3 Replies

8. Shell Programming and Scripting

PHP script to modify .forward files

Hi. I've been racking my brain on a project I've been working on for work, and hope someone here might be of assistance. Basically I'm trying to create dynamically generated .forward files for users/aliases on my email server. The intent is for these files to be generated automatically any time... (3 Replies)
Discussion started by: adotte
3 Replies

9. Shell Programming and Scripting

[php] ftp get all files from a certain file type

Hi all, I googled for this kind of function but didn't find anything. I have an FTP connection with a server, went to the dir. In this dir there are several TXT files. I would like to have function that downloads all this files, based on their .txt extension. In bash, for example, simply:... (10 Replies)
Discussion started by: laurens
10 Replies

10. Shell Programming and Scripting

GD.dll files for php 5.1.6

Hi, I want to create an image dynamically. I used this function. $img_handle = ImageCreate ($length, 10) or die ("Cannot Create image"); It was not creating the image. When i checked in error_log file the error was: PHP Fatal error: Call to undefined function ImageCreate(). ... (0 Replies)
Discussion started by: vanitham
0 Replies
Login or Register to Ask a Question