Sanitize short string of text to single line without HTML

  • This sanitizer is useful for short strings of input text like like first and last names, street names, search queries, etc.

  • Please note the default 255 character max length setting.

  • If using returned value for front-end output, be sure to run it through $sanitizer->entities() first.


$str = "
  <strong>Hello World</strong>
  How are you doing today?

echo $sanitizer->text($str);
// outputs: Hello World How are you doing today?


// basic usage
$string = $sanitizer->text(string $value);

// usage with all arguments
$string = $sanitizer->text(string $value, array $options = []);



String value to sanitize

$options (optional)array

Options to modify default behavior:

  • maxLength (int): maximum characters allowed, or 0=no max (default=255).
  • maxBytes (int): maximum bytes allowed (default=0, which implies maxLength*4).
  • stripTags (bool): strip markup tags? (default=true).
  • stripMB4 (bool): strip emoji and other 4-byte UTF-8? (default=false).
  • allowableTags (string): markup tags that are allowed, if stripTags is true (use same format as for PHP's strip_tags() function.
  • multiLine (bool): allow multiple lines? if false, then $newlineReplacement below is applicable (default=false).
  • newlineReplacement (string): character to replace newlines with, OR specify boolean TRUE to remove extra lines (default=" ").
  • inCharset (string): input character set (default="UTF-8").
  • outCharset (string): output character set (default="UTF-8").

Return value


See Also

$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.84