You are here

function _no_nbsp_eraser in No Non-breaking Space Filter 7

Same name and namespace in other branches
  1. 8 no_nbsp.module \_no_nbsp_eraser()

Erase the string ' '.

Parameters

string $text: A string to pass through the eraser.

bool $preserve_placeholders: Perserve non-breaking spaces, that serve as placeholders.

Return value

string The erased string.

3 calls to _no_nbsp_eraser()
NoNbspUnitTestCase::testFunctionNoNbspEraser in ./no_nbsp.test
Test the function _no_nbsp_eraser.
no_nbsp_field_formatter_view in ./no_nbsp.module
Implements hook_field_formatter_view().
_no_nbsp_process in ./no_nbsp.module
Implements hook_filter_FILTER_process().

File

./no_nbsp.module, line 128
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);
}