PlainTextOutput.php 653 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace Drupal\Component\Render;
  3. use Drupal\Component\Utility\Html;
  4. /**
  5. * Provides an output strategy for transforming HTML into simple plain text.
  6. *
  7. * Use this when rendering a given HTML string into a plain text string that
  8. * does not need special formatting, such as a label or an email subject.
  9. *
  10. * Returns a string with HTML tags stripped and HTML entities decoded suitable
  11. * for email or other non-HTML contexts.
  12. */
  13. class PlainTextOutput implements OutputStrategyInterface {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public static function renderFromHtml($string) {
  18. return Html::decodeEntities(strip_tags((string) $string));
  19. }
  20. }