$sanitizer->text() method

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.

Example

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

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

Usage

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

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

Arguments

NameType(s)Description
valuestring

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).
  • stripQuotes (bool): strip out any "quote" or 'quote' characters? Specify true, or character to replace with. (default=false)
  • stripSpace (bool|string): strip whitespace? Specify true or character to replace whitespace with (default=false). Since 3.0.105
  • reduceSpace (bool|string): reduce consecutive whitespace to single? Specify true or character to reduce to (default=false). Note that the reduceSpace option is an alternative to the stripSpace option, they should not be used together. Since 3.0.105
  • 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).
  • convertEntities (bool): convert HTML entities to equivalent character(s)? (default=false). Since 3.0.105
  • newlineReplacement (string): character to replace newlines with, OR specify boolean true to remove extra lines (default=" ").
  • truncateTail (bool): if truncate necessary for maxLength, truncate from end/tail? Use false to truncate head (default=true). Since 3.0.105
  • inCharset (string): input character set (default="UTF-8").
  • outCharset (string): output character set (default="UTF-8").

Return value

string

See Also


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #284
    In the 284th issue of ProcessWire Weekly we're going to take a quick look at the latest core updates, introduce a new module called InputfieldFloatRange, and continue our ongoing poll series #processwireworks. Read on!
    Weekly.pw / 20 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, and the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer