You are here

function simplenews_html_to_text in Simplenews 7.2

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_html_to_text()
  2. 6.2 includes/simplenews.mail.inc \simplenews_html_to_text()
  3. 6 simplenews.module \simplenews_html_to_text()
  4. 7 includes/simplenews.mail.inc \simplenews_html_to_text()

HTML to text conversion for HTML and special characters.

Converts some special HTML characters in addition to drupal_html_to_text()

Parameters

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

boolean $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 simplenews_html_to_text()
SimplenewsSourceEntity::getBodyWithFormat in includes/simplenews.source.inc
Get the body with the requested format.

File

includes/simplenews.mail.inc, line 691
Simplenews email send and spool handling

Code

function simplenews_html_to_text($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 drupal_html_to_text().
  // 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, '_simplenews_absolute_mail_urls', $text);
  }

  // Replace some special characters before performing the drupal standard conversion.
  $preg = _simplenews_html_replace();
  $text = preg_replace(array_keys($preg), array_values($preg), $text);

  // Perform standard drupal html to text conversion.
  return drupal_html_to_text($text);
}