How to get rid of control M character

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alain Forget

    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
  • Tim Van Wassenhove

    #2
    Re: How to get rid of control M character

    On 2003-12-05, Alain Forget <AlainHPC@hotma il.com> wrote:[color=blue]
    > 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.[/color]

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

    --
    verum ipsum factum

    Comment

    • Justin Koivisto

      #3
      Re: How to get rid of control M character

      Tim Van Wassenhove wrote:
      [color=blue]
      > On 2003-12-05, Alain Forget <AlainHPC@hotma il.com> wrote:
      >[color=green]
      >>From the WWW interface everything seems OK, but when I look to the
      >>file, each line has a "^M" (control-M) at the end.[/color]
      >
      > Just run dos2unix on the files. (this will remove the <cr>)[/color]

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

      $contents=preg_ replace('/(\r\n|\r|\n)/s',"\n",$conten ts);

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

      Comment

      • Chung Leong

        #4
        Re: How to get rid of control M character

        Use strtr(). It's designed for situations like yours.

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

        Uzytkownik "Alain Forget" <AlainHPC@hotma il.com> napisal w wiadomosci
        news:dc666117.0 312050814.6baa3 237@posting.goo gle.com...[color=blue]
        > 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[/color]


        Comment

        • Alain Forget

          #5
          Re: How to get rid of control M character

          Justin Koivisto <spam@koivi.com > wrote in message news:<ez2Ab.148 4$Uz.48664@news 7.onvoy.net>...[color=blue]
          > Tim Van Wassenhove wrote:
          >[color=green]
          > > On 2003-12-05, Alain Forget <AlainHPC@hotma il.com> wrote:
          > >[color=darkred]
          > >>From the WWW interface everything seems OK, but when I look to the
          > >>file, each line has a "^M" (control-M) at the end.[/color]
          > >
          > > Just run dos2unix on the files. (this will remove the <cr>)[/color]
          >
          > If you don't have access to that, before writing the file use something
          > like:
          >
          > $contents=preg_ replace('/(\r\n|\r|\n)/s',"\n",$conten ts);[/color]

          Justin,

          The preg_replace command acts like magic on my files.

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

          Alain

          Comment

          Working...