FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Re: DOS newlines (CR/LF) to Unix format
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: DOS newlines (CR/LF) to Unix format [message #171731] Wed, 19 January 2011 11:24 Go to previous message
Kim Andr Aker is currently offline  Kim Andr Aker
Messages: 17
Registered: September 2010
Karma:
Junior Member
På Wed, 19 Jan 2011 11:59:48 +0100, skrev Bjarne Jensen
<bjarne(dot)b(dot)jensen(at)gmail(dot)com>:

> I found this snippet on internet:
>
> # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
> awk '{sub(/\r$/,"");print}' # assumes EACH line ends with Ctrl-M
>
> It works fine on the commandline so I wrote like this in a php-script:
>
> - - -
>
> $unix = ".unix";
>
> foreach (glob($usedir."[12_]*") as $filename) {
> exec('awk { sub("/\r$", ""); print } $filename > $filename.$unix');
> }
>
> - - -
>
>
> But absolutely nothing happens!
>
> Why not?

It's probably either one of two reasons, or a combination of the two.

One, your glob() function may not return any items.

Two, your system may have disabled the use of the exec(), passthru()
and/or system() functions due to security. In any case, running a command
for this in PHP is not needed, just use the built-in PHP functions instead.

Assuming you use PHP 5, and that your use of the glob() function is
correct:

$unix = ".unix";

foreach (glob($usedir."[12_]*") as $filename) {
// doing this in a single operation
file_put_contents($filename.$unix, str_replace("\r", "",
file_get_contents($filename)));
}


--
Kim André Akerø
- kimandre(at)NOSPAMbetadome(dot)com
(remove NOSPAM to contact me directly)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: fatal error: cannot redeclare
Next Topic: getting file from <option>
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Oct 18 09:16:54 GMT 2024

Total time taken to generate the page: 0.07314 seconds