You are here

public static function MailFormatHelper::htmlToText in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Mail/MailFormatHelper.php \Drupal\simplenews\Mail\MailFormatHelper::htmlToText()
  2. 3.x src/Mail/MailFormatHelper.php \Drupal\simplenews\Mail\MailFormatHelper::htmlToText()

HTML to text conversion for HTML and special characters.

Converts some special HTML characters in addition to \Drupal\Core\Mail\MailFormatHelper\MailFormatHelper::htmlToText().

Parameters

string $text: The mail text with HTML and special characters.

bool $inline_hyperlinks: TRUE: URLs will be placed inline. FALSE: URLs will be converted to numbered reference list.

Return value

string The target text with HTML and special characters replaced.

1 call to MailFormatHelper::htmlToText()
MailEntity::getBodyWithFormat in src/Mail/MailEntity.php
Get the body with the requested format.

File

src/Mail/MailFormatHelper.php, line 29

Class

MailFormatHelper
Extended mail formatter helpers.

Namespace

Drupal\simplenews\Mail

Code

public static function htmlToText($text, $inline_hyperlinks = TRUE) {

  // By replacing <a> tag by only its URL the URLs will be placed inline
  // in the email body and are not converted to a numbered reference list
  // by MailFormatHelper::htmlToText().
  // URL are converted to absolute URL as drupal_html_to_text() would have.
  if ($inline_hyperlinks) {
    $pattern = '@<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>@is';
    $text = preg_replace_callback($pattern, '\\Drupal\\simplenews\\Mail\\MailFormatHelper::absoluteMailUrls', $text);
  }

  // Perform standard drupal html to text conversion.
  return CoreMailFormatHelper::htmlToText($text);
}