function simplenews_html_to_text in Simplenews 5
Same name and namespace in other branches
- 6.2 includes/simplenews.mail.inc \simplenews_html_to_text()
- 6 simplenews.module \simplenews_html_to_text()
- 7.2 includes/simplenews.mail.inc \simplenews_html_to_text()
- 7 includes/simplenews.mail.inc \simplenews_html_to_text()
Convert html text to plain text.
Conversion of html tags, special characters and anchor and image tags. URLs in anchor and image tags are converted to absolute URLs and, depending on admin setting, placed in-line or at the bottom of the email.
Parameters
string $txt: html text string
boolean $inline: TRUE = anchor and image tags are converted in-line; FALSE = anchor and image tags are converted and placed at the bottom of the message.
Return value
string converted plain text string
1 call to simplenews_html_to_text()
- simplenews_node_prepare in ./
simplenews.module - Prepare node for sending
File
- ./
simplenews.module, line 1427
Code
function simplenews_html_to_text($txt, $inline) {
$pattern = '@(<a[^>]+?href="(.\\S+?)"[^>]*>(.+?)</a>)|(<img[^>]+?src="([^"]*)"[^>]*?>)@eis';
if ($inline) {
$txt = preg_replace($pattern, "_simplenews_mail_uri('\\2\\5', '\\3')", $txt);
}
else {
// Converted 'a' and 'img' URLs are converted by and stored in _simplenews_mail_urls().
$txt = preg_replace($pattern, "'\\3 ['. _simplenews_mail_urls('\\2\\5') .']'", $txt);
// Retreive array of URLs from _simplenews_mail_urls() and format them
// as a list at the end of the message.
$urls = _simplenews_mail_urls();
if (count($urls)) {
$txt .= "\n";
$i = 0;
for ($max = count($urls); $i < $max; $i++) {
$txt .= '[' . ($i + 1) . '] ' . $urls[$i] . "\n";
}
}
// Empty the the stored list of URLs.
_simplenews_mail_urls(0, TRUE);
}
// some basic html to text conversion
$txt = preg_replace(_simplenews_define_search(), _simplenews_define_replace(), $txt);
$txt = preg_replace("/\n\\s+\n/", "\n\n", $txt);
$txt = strip_tags($txt);
$txt = decode_entities($txt);
return wordwrap($txt, 80);
}