normalizeBreaks() public static method

Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. Defaults to CRLF (for message bodies) and preserves consecutive breaks.
public static normalizeBreaks ( string $text, string $breaktype = " " ) : string
$text string
$breaktype string What kind of line break to use, defaults to CRLF
return string
 /**
  * Test line break reformatting
  */
 public function testLineBreaks()
 {
     $unixsrc = "hello\nWorld\nAgain\n";
     $macsrc = "hello\rWorld\rAgain\r";
     $windowssrc = "hello\r\nWorld\r\nAgain\r\n";
     $mixedsrc = "hello\nWorld\rAgain\r\n";
     $target = "hello\r\nWorld\r\nAgain\r\n";
     $this->assertEquals($target, PHPMailer::normalizeBreaks($unixsrc), 'UNIX break reformatting failed');
     $this->assertEquals($target, PHPMailer::normalizeBreaks($macsrc), 'Mac break reformatting failed');
     $this->assertEquals($target, PHPMailer::normalizeBreaks($windowssrc), 'Windows break reformatting failed');
     $this->assertEquals($target, PHPMailer::normalizeBreaks($mixedsrc), 'Mixed break reformatting failed');
 }
 /**
  * Send email(s).
  *
  * @since 2.5.0
  *
  * @param BP_Email $email Email to send.
  * @return bool|WP_Error Returns true if email send, else a descriptive WP_Error.
  */
 public function bp_email(BP_Email $email)
 {
     static $phpmailer = null;
     if ($phpmailer === null) {
         if (!class_exists('PHPMailer')) {
             require_once ABSPATH . WPINC . '/class-phpmailer.php';
             require_once ABSPATH . WPINC . '/class-smtp.php';
         }
         $phpmailer = new PHPMailer(true);
     }
     /*
      * Resets.
      */
     $phpmailer->clearAllRecipients();
     $phpmailer->clearAttachments();
     $phpmailer->clearCustomHeaders();
     $phpmailer->clearReplyTos();
     $phpmailer->Sender = '';
     /*
      * Set up.
      */
     $phpmailer->IsMail();
     $phpmailer->CharSet = bp_get_option('blog_charset');
     $phpmailer->Hostname = self::get_hostname();
     /*
      * Content.
      */
     $phpmailer->Subject = $email->get_subject('replace-tokens');
     $content_plaintext = PHPMailer::normalizeBreaks($email->get_content_plaintext('replace-tokens'));
     if ($email->get('content_type') === 'html') {
         $phpmailer->msgHTML($email->get_template('add-content'), '', 'wp_strip_all_tags');
         $phpmailer->AltBody = $content_plaintext;
     } else {
         $phpmailer->IsHTML(false);
         $phpmailer->Body = $content_plaintext;
     }
     $recipient = $email->get_from();
     try {
         $phpmailer->SetFrom($recipient->get_address(), $recipient->get_name(), false);
     } catch (phpmailerException $e) {
     }
     $recipient = $email->get_reply_to();
     try {
         $phpmailer->addReplyTo($recipient->get_address(), $recipient->get_name());
     } catch (phpmailerException $e) {
     }
     $recipients = $email->get_to();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddAddress($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_cc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddCc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_bcc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddBcc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $headers = $email->get_headers();
     foreach ($headers as $name => $content) {
         $phpmailer->AddCustomHeader($name, $content);
     }
     /**
      * Fires after PHPMailer is initialised.
      *
      * @since 2.5.0
      *
      * @param PHPMailer $phpmailer The PHPMailer instance.
      */
     do_action('bp_phpmailer_init', $phpmailer);
     /** This filter is documented in wp-includes/pluggable.php */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     try {
         return $phpmailer->Send();
     } catch (phpmailerException $e) {
         return new WP_Error($e->getCode(), $e->getMessage(), $email);
     }
 }