You are here

public static function WebformHtmlHelper::toPlainText in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformHtmlHelper.php \Drupal\webform\Utility\WebformHtmlHelper::toPlainText()

Convert HTML markup to plain text.

Parameters

string $string: Text that may contain HTML markup and encode characters.

Return value

string Text with HTML markup removed and special characters decoded.

3 calls to WebformHtmlHelper::toPlainText()
TextBase::prepare in src/Plugin/WebformElement/TextBase.php
Prepare an element to be rendered within a webform.
WebformElementBase::prepare in src/Plugin/WebformElementBase.php
Prepare an element to be rendered within a webform.
WebformHtmlHelperTest::testToPlainText in tests/src/Unit/Utility/WebformHtmlHelperTest.php
Tests WebformHtmlHelper::containsToPlainText().

File

src/Utility/WebformHtmlHelper.php, line 24

Class

WebformHtmlHelper
Provides HTML helper functions.

Namespace

Drupal\webform\Utility

Code

public static function toPlainText($string) {
  if (static::containsHtml($string)) {
    $string = strip_tags($string);
    $string = Html::decodeEntities($string);
    return $string;
  }
  else {
    return $string;
  }
}