$sanitizer→selectorValue()
Sanitizes a string value that needs to go in a ProcessWire selector
Always use this to sanitize any string values you are inserting in selector strings. This ensures that the value can't be confused for another component of the selector string. This method may remove characters, escape characters, or surround the string in quotes.
Example
// Sanitize text for a search on title and body fields
$q = $input->get->text('q'); // text search query
$results = $pages->find("title|body%=" . $sanitizer->selectorValue($q));
// In 3.0.127 you can also provide an array for the $value argument
$val = $sanitizer->selectorValue([ 'foo', 'bar', 'baz' ]);
echo $val; // outputs: foo|bar|bazUsage
// basic usage
$string = $sanitizer->selectorValue($value);
// usage with all arguments
$string = $sanitizer->selectorValue($value, $options = []);Arguments
| Name | Type(s) | Description |
|---|---|---|
$value | string array | String value to sanitize (assumed to be UTF-8), or in 3.0.127+ you may use an array and it will be sanitized to an OR value string. |
$options (optional) | array int | Options to modify behavior. Note version 1 supports only
|
Return value
string int bool mixedValue ready to be used as the value component in a selector string. Always returns string unless you specify something different for 'emptyValue' option.
$sanitizer methods and properties
API reference based on ProcessWire core version 3.0.253