You are here

protected static function SocialContent::validateText in Social Content 7.2

Strip non utf8 characters that can sometimes come through.

Helper function, used by modules implementing social content types.

Parameters

mixed $text: Filtered text.

Return value

string The stripped text.

1 call to SocialContent::validateText()
SocialContent::attachFields in ./social_content.class.inc
Attach declare fields onto wrapper.

File

./social_content.class.inc, line 1055
Social Content class.

Class

SocialContent
TODO: Table names should be a property for ease of change Separate this class into smaller classes.

Code

protected static function validateText($text) {
  if (is_array($text)) {
    if (!isset($text['value'])) {
      return $text;
    }
    $raw =& $text['value'];
  }
  else {
    $raw =& $text;
  }

  // The following regular expression will replace 4-byte UTF-8 characters,
  // if this doesn't happen, then there will be sql insertion errors
  // see http://stackoverflow.com/questions/16496554/can-php-detect-4-byte-encoded-utf8-chars/16496799#16496799
  $raw = preg_replace('%(?:
              \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2}      # planes 1-3
            | [\\xF1-\\xF3][\\x80-\\xBF]{3}          # planes 4-15
            | \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}      # plane 16
        )%xs', '', $raw);
  return $text;
}