function _no_nbsp_eraser in No Non-breaking Space Filter 8
Same name and namespace in other branches
- 7 no_nbsp.module \_no_nbsp_eraser()
Erase the string ' '.
Parameters
string $text: A string to pass through the eraser.
bool $preserve_placeholders: Preserve non-breaking spaces, that serve as placeholders.
Return value
string The erased string.
3 calls to _no_nbsp_eraser()
- FilterNoNbsp::process in src/
Plugin/ Filter/ FilterNoNbsp.php - Performs the filter processing.
- NoNbspFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ NoNbspFormatter.php - Builds a renderable array for a field value.
- UnitTest::testFunctionNoNbspEraser in src/
Tests/ UnitTest.php - Test the function _no_nbsp_eraser.
File
- ./
no_nbsp.module, line 31 - A filter module that deletes all non-breaking spaces.
Code
function _no_nbsp_eraser($text, $preserve_placeholders = FALSE) {
if ($preserve_placeholders) {
// See https://stackoverflow.com/a/50301496.
$text = preg_replace("/([^>]) /ui", "\$1 ", $text);
}
else {
$text = preg_replace('/ /i', ' ', $text);
}
return preg_replace('/ +/i', ' ', $text);
}