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
Name | Type(s) | Description |
---|
$value | string | String value to sanitize |
$options (optional) | array | Options to modify default behavior: maxLength (int): maximum characters allowed, or 0=no max Default:255maxBytes (int): maximum bytes allowed Default:0, which implies maxLength*4stripTags (bool): strip markup tags? Default:truestripMB4 (bool): strip emoji and other 4-byte UTF-8? Default:falsestripQuotes (bool): strip out any "quote" or 'quote' characters? Specify true, or character to replace with. Default:falsestripSpace (bool|string): strip whitespace? Specify true or character to replace whitespace with Default:false 3.0.105reduceSpace (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. 3.0.105allowableTags (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:falseconvertEntities (bool): convert HTML entities to equivalent character(s)? Default:false 3.0.105newlineReplacement (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 3.0.105inCharset (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.251