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 #171904 is a reply to message #171731] Thu, 20 January 2011 18:58 Go to previous message
Bjarne Jensen is currently offline  Bjarne Jensen
Messages: 9
Registered: January 2011
Karma:
Junior Member
Hej Kim,

Mange tak - det funker!

Mvh Bjarne

- - -



On 2011-01-19 12:24, Kim André Akerø wrote:
> 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)));
> }
>
>
[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: Sun Nov 24 23:31:11 GMT 2024

Total time taken to generate the page: 0.05230 seconds