function MailFormatHelper::htmlToTextPad

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Mail/MailFormatHelper.php \Drupal\Core\Mail\MailFormatHelper::htmlToTextPad()
  2. 10 core/lib/Drupal/Core/Mail/MailFormatHelper.php \Drupal\Core\Mail\MailFormatHelper::htmlToTextPad()
  3. 11.x core/lib/Drupal/Core/Mail/MailFormatHelper.php \Drupal\Core\Mail\MailFormatHelper::htmlToTextPad()

Pads the last line with the given character.

Parameters

string $text: The text to pad.

string $pad: The character to pad the end of the string with.

string $prefix: (optional) Prefix to add to the string.

Return value

string The padded string.

See also

\Drupal\Core\Mail\MailFormatHelper::htmlToText()

1 call to MailFormatHelper::htmlToTextPad()
MailFormatHelper::htmlToText in core/lib/Drupal/Core/Mail/MailFormatHelper.php
Transforms an HTML string into plain text, preserving its structure.

File

core/lib/Drupal/Core/Mail/MailFormatHelper.php, line 380

Class

MailFormatHelper
Defines a class containing utility methods for formatting mail messages.

Namespace

Drupal\Core\Mail

Code

protected static function htmlToTextPad($text, $pad, $prefix = '') {
    // Remove last line break.
    $text = substr($text, 0, -1);
    // Calculate needed padding space and add it.
    if (($p = strrpos($text, "\n")) === FALSE) {
        $p = -1;
    }
    $n = max(0, 79 - (strlen($text) - $p) - strlen($prefix));
    // Add prefix and padding, and restore linebreak.
    return $text . $prefix . str_repeat($pad, $n) . "\n";
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.