Jyxo\StringUtil::fixLineEnding PHP Method

fixLineEnding() public static method

Fixes and unifies line endings in a string.
public static fixLineEnding ( string $string, string $lineEnd = " " ) : string
$string string String to fix
$lineEnd string Desired line ending
return string
    public static function fixLineEnding(string $string, string $lineEnd = "\n") : string
    {
        $string = str_replace("\r\n", "\n", $string);
        $string = str_replace("\r", "\n", $string);
        $string = str_replace("\n", $lineEnd, $string);
        return $string;
    }

Usage Example

Beispiel #1
0
 /**
  * Adds all attachments to the email.
  *
  * @return string
  */
 private function attachAll() : string
 {
     $mime = [];
     foreach ($this->email->attachments as $attachment) {
         $encoding = !empty($attachment->encoding) ? $attachment->encoding : Encoding::BASE64;
         $name = $this->changeCharset($this->clearHeaderValue($attachment->name));
         $mime[] = '--' . $this->boundary[1] . self::LINE_END;
         $mime[] = 'Content-Type: ' . $this->clearHeaderValue($attachment->mimeType) . ';' . self::LINE_END;
         $mime[] = ' name="' . $this->encodeHeader($name) . '"' . self::LINE_END;
         $mime[] = 'Content-Transfer-Encoding: ' . $encoding . self::LINE_END;
         if ($attachment->isInline()) {
             $mime[] = 'Content-ID: <' . $this->clearHeaderValue($attachment->cid) . '>' . self::LINE_END;
         }
         $mime[] = 'Content-Disposition: ' . $attachment->disposition . ';' . self::LINE_END;
         $mime[] = ' filename="' . $this->encodeHeader($name) . '"' . self::LINE_END . self::LINE_END;
         // Just fix line endings in case of encoded attachments, encode otherwise
         $mime[] = !empty($attachment->encoding) ? \Jyxo\StringUtil::fixLineEnding($attachment->content, self::LINE_END) : $this->encodeString($attachment->content, $encoding);
         $mime[] = self::LINE_END . self::LINE_END;
     }
     $mime[] = '--' . $this->boundary[1] . '--' . self::LINE_END;
     return implode('', $mime);
 }
All Usage Examples Of Jyxo\StringUtil::fixLineEnding