Find escaped characters in $str, replace them with a placeholder, and return the placeholders
Usage
Available since version 3.0.162.
Example
// 1. Escape certain chars in a string that you want to survive some processing:
$str = 'Hello \*world\* foo \"bar\" baz';
// 2. Use this method to find escape chars and replace them temporarily:
$a = $sanitizer->getTextTools()->findReplaceEscapeChars($str, [ '*', '"' ]);
// 3. Process string with anything that you want NOT to see chars that were escaped:
$str = some_function_that_processes_the_string($str);
// 4. Do this to restore the escaped chars (restored without backslashes by default):
$str = str_replace(array_keys($a), array_values($a), $str);
Usage
// basic usage
$array = $wireTextTools->findReplaceEscapeChars($str, array $escapeChars);
// usage with all arguments
$array = $wireTextTools->findReplaceEscapeChars($str, array $escapeChars, array $options = []);
Arguments
Name | Type(s) | Description |
---|---|---|
str | ||
escapeChars | array | Array of chars you want to escape i.e. [ '*', '[', ']', '(', ')', '`', '_', '\', '"' ] |
options (optional) | array | Options to modify behavior:
|
Return value
array
Returns assoc array where keys are placeholders substituted in $str and values are escaped characters.
WireTextTools methods and properties
API reference based on ProcessWire core version 3.0.236