[PHP-users 21019]Re: Windowsで改行が重複

makino k-m @ hyper.cx
2004年 3月 27日 (土) 13:58:42 JST


牧野です。

私ならこの様にしますが。
参考になれば。(手抜きですが...)
<?php
$file = 'test.txt';

// test.txt読み込み
$fp = @fopen($file, 'rb') or die("{$file}が読み込めません");
$html = fread($fp, filesize($file));
fclose($fp);
unset($fp);
echo("<pre>");
echo("元のデータ\n");
print_r($html);
echo("+++++\n");
echo("変換データ\n");
// 改行を除去
$html = preg_replace("/\r\n\r\n|\n\n/", "\n", $html);

print_r($html);

$fp = @fopen('copy.txt', 'ab') or die("copy.txtが開けません");
fwrite($fp, $html);
fclose($fp);

?>

ところで、Unix/Linux と Windowsの改行コードの違いを理解していますか?
マニュアルのファイル関連を熟読してみて下さい。


Sat, 27 Mar 2004 13:03:55 +0900
fh<foolhill @ s50.xrea.com> -wrote:
> 解決のヒントなどございましたらお教えください。


/*++++++++++++++++++++++++++++++++
 * 牧野 <k-m @ hyper.cx>
 *++++++++++++++++++++++++++++++++
 */





PHP-users メーリングリストの案内