tags:

views:

95

answers:

2
[root@file Engineer]# ls resume_Al_Kassar_9-29-08.doc.txt^M 
resume_Al_Kassar_9-29-08.doc.txt?
[root@file Engineer]#

But I browse into that directory by "File Transfer Window",didn't see ^M at all

it's simply "resume_Al_Kassar_9-29-08.doc.txt"

Any anyone step into this issue ever?And how to solve this?

This .txt^M file is generated by another program,and is processed by "bashFileConvert" function(it's a PHP function).

$toF = bashFileConvert($toF);//this step generated ^M
$cmd = "$parser $file $arrow_str $toF";

How can I get rid of this annoying ^M?

Later on I found:

$arrow_str = $arrow ? '>' : '';
$file = bashFileConvert($file);
$toF = bashFileConvert($toF);
$cmd = "$parser $file $arrow_str $toF";
echo $cmd . "\r\n";
file_put_contents('resumeSh',$cmd."\r\n",FILE_APPEND);

It should be the last line that caused this issue!

+3  A: 

Some where you get a 'carrage return' character added to your filename, might be a msdos/unix textfile missmatch somewhere. msdos is \r\n and unix only \n, ^M is \r (carrage return) i belive.

Joakim Elofsson
I updated my post,telling which step generated the ^M mark.
Shore
You're going to need to show the code for the bashFileConvert function - this is adding the extraneous ^M character
1800 INFORMATION
I think maybe I've found the reason,see my update.
Shore
+1  A: 

This is definitely a line endings issue. Most likely your PHP function is splitting text by \n , and your input actually is \r\n. You can convert your input to one line ending type by doing something like:

$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", "\n", $data);

Now $data will only contain \n line breaks.

Edit after clarification

Don't use \r\n, just use \n and everything should be fine.

NilObject
I updated my post,telling which step generated the ^M mark.
Shore