469,353 Members | 2,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

How to get rid of control M character

Hi,

I'm using PHP code to develop a www interface to let users edit text
files stored on a Solaris UX server. Users are using Windows based
WWW browser access this web site. Once they have selected the file
they want to edit, it's presented in a text window (form) so thay can
modify the file.

The submit button passes the contents of the field to a variable and
it is saved to disc.

From the WWW interface everything seems OK, but when I look to the
file, each line has a "^M" (control-M) at the end.

This makes the files bigger and it can cause problem in a near future
because these files have to be processed by shell scripts to populate
a mySQL DB.

Someone has seen that before and what was the solution.

Thanks,
Alain
Jul 17 '05 #1
4 16628
On 2003-12-05, Alain Forget <Al******@hotmail.com> wrote:
Hi,

I'm using PHP code to develop a www interface to let users edit text
files stored on a Solaris UX server. Users are using Windows based
WWW browser access this web site. Once they have selected the file
they want to edit, it's presented in a text window (form) so thay can
modify the file.

The submit button passes the contents of the field to a variable and
it is saved to disc.

From the WWW interface everything seems OK, but when I look to the
file, each line has a "^M" (control-M) at the end.


Just run dos2unix on the files. (this will remove the <cr>)

--
verum ipsum factum
Jul 17 '05 #2
Tim Van Wassenhove wrote:
On 2003-12-05, Alain Forget <Al******@hotmail.com> wrote:
From the WWW interface everything seems OK, but when I look to the
file, each line has a "^M" (control-M) at the end.


Just run dos2unix on the files. (this will remove the <cr>)


If you don't have access to that, before writing the file use something
like:

$contents=preg_replace('/(\r\n|\r|\n)/s',"\n",$contents);

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #3
Use strtr(). It's designed for situations like yours.

$text = strtr($text, array("\r" => ""));

Uzytkownik "Alain Forget" <Al******@hotmail.com> napisal w wiadomosci
news:dc**************************@posting.google.c om...
Hi,

I'm using PHP code to develop a www interface to let users edit text
files stored on a Solaris UX server. Users are using Windows based
WWW browser access this web site. Once they have selected the file
they want to edit, it's presented in a text window (form) so thay can
modify the file.

The submit button passes the contents of the field to a variable and
it is saved to disc.

From the WWW interface everything seems OK, but when I look to the
file, each line has a "^M" (control-M) at the end.

This makes the files bigger and it can cause problem in a near future
because these files have to be processed by shell scripts to populate
a mySQL DB.

Someone has seen that before and what was the solution.

Thanks,
Alain

Jul 17 '05 #4
Justin Koivisto <sp**@koivi.com> wrote in message news:<ez*****************@news7.onvoy.net>...
Tim Van Wassenhove wrote:
On 2003-12-05, Alain Forget <Al******@hotmail.com> wrote:
From the WWW interface everything seems OK, but when I look to the
file, each line has a "^M" (control-M) at the end.


Just run dos2unix on the files. (this will remove the <cr>)


If you don't have access to that, before writing the file use something
like:

$contents=preg_replace('/(\r\n|\r|\n)/s',"\n",$contents);


Justin,

The preg_replace command acts like magic on my files.

THANK YOU, THANK YOU ... 1000 times....!!! ;-)

Alain
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Marco Montel | last post: by
1 post views Thread by coolcoon | last post: by
2 posts views Thread by zdrakec | last post: by
15 posts views Thread by pkaeowic | last post: by
5 posts views Thread by Sebastian Araya | last post: by
4 posts views Thread by R.A.M. | last post: by
7 posts views Thread by wannymahoots | last post: by
10 posts views Thread by Paul W | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.