Go to English page

ViaThinkSoft CodeLib

Dieser Artikel befindet sich in der Kategorie:
CodeLib → Programmierhilfen → PHP

Empfehlung: In einem OpenSource-Projekt ALLE Dateien in das DOS-Format (CRLF) konvertieren. Begrüund: Dieses Format kann von dann sowohl von nativen Windows-Anwendungen als auch von Linux und Macintosh gelesen werden. Außerdem erfordern fast alle Protokolle das CRLF anstelle eines einzelnen LF.

<?php

define
('CR', "\r");
define('LF', "\n");
define('CRLF', CR.LF);

function 
normalizeToUnixLineBreaks($text, &$count_crlf=0, &$count_cr=0, &$count_lf=0) {
    
$text = str_replace(CRLF, LF, $text, $count_crlf);
    
$text = str_replace(CR, LF, $text, $count_cr);
    
$count_lf = substr_count($text, LF) - $count_crlf - $count_cr;

    return 
$text;
}

function 
normalizeToWindowsLineBreaks($text, &$count_crlf=0, &$count_cr=0, &$count_lf=0) {
    
$text = normalizeToUnixLineBreaks($text, $count_crlf, $count_cr, $count_lf);

    
$text = str_replace(LF, CRLF, $text);

    return 
$text;
}

function 
normalizeToMacintoshLineBreaks($text, &$count_crlf=0, &$count_cr=0, &$count_lf=0) {
    
$text = normalizeToUnixLineBreaks($text, $count_crlf, $count_cr, $count_lf);

    
$text = str_replace(LF, CR, $text);

    return 
$text;
}

?>
Daniel Marschall
ViaThinkSoft Mitbegründer