You are here

public function RemoveHtmlComments::removeHtmlCommentsFromString in Twig - Remove HTML comments 8

Removes HTML comments from string.

Example: A string which has value <!--Start DEBUG--> ABCD <!--End DEBUG--> will be returned the output ABCD after using the the following function.

Parameters

string|null $string: A string or NULL.

Return value

string The string without HTML comments.

1 call to RemoveHtmlComments::removeHtmlCommentsFromString()
RemoveHtmlComments::removeHtmlCommentsAsRenderArray in src/TwigExtension/RemoveHtmlComments.php
Removes HTML comments from string.

File

src/TwigExtension/RemoveHtmlComments.php, line 83

Class

RemoveHtmlComments
Provides a Twig filter that removes HTML comments from input.

Namespace

Drupal\twig_remove_html_comments\TwigExtension

Code

public function removeHtmlCommentsFromString(?string $string) : string {
  if ($string !== NULL) {
    return preg_replace('/<!--(.|\\s)*?-->\\s*|\\r|\\n/', '', $string);
  }
  else {
    return '';
  }
}