You are here

function tweet_feed_filter_iconv_text in Tweet Feed 8.3

Same name and namespace in other branches
  1. 7.3 tweet_feed.module \tweet_feed_filter_iconv_text()
  2. 4.x tweet_feed.module \tweet_feed_filter_iconv_text()

Filter iconv from text.

1 call to tweet_feed_filter_iconv_text()
TweetEntity::setUserMentions in src/Entity/TweetEntity.php

File

./tweet_feed.module, line 171
Contains tweet_feed.module.

Code

function tweet_feed_filter_iconv_text($text, $replace = '--') {

  // The tweet author goes into the title field
  // Filter it cleanly since it is going into the title field. If we cannot use iconv,
  // then use something more primitive, but effective
  // @see https://www.drupal.org/node/1910376
  // @see http://webcollab.sourceforge.net/unicode.html
  // Reject overly long 2 byte sequences, as well as characters above U+10000
  // and replace with --.
  $altered = preg_replace('/[\\x00-\\x08\\x10\\x0B\\x0C\\x0E-\\x19\\x7F]' . '|[\\x00-\\x7F][\\x80-\\xBF]+' . '|([\\xC0\\xC1]|[\\xF0-\\xFF])[\\x80-\\xBF]*' . '|[\\xC2-\\xDF]((?![\\x80-\\xBF])|[\\x80-\\xBF]{2,})' . '|[\\xE0-\\xEF](([\\x80-\\xBF](?![\\x80-\\xBF]))|(?![\\x80-\\xBF]{2})|[\\x80-\\xBF]{3,})/S', '--', $text);

  // Reject overly long 3 byte sequences and UTF-16 surrogates and replace
  // with --.
  return preg_replace('/\\xE0[\\x80-\\x9F][\\x80-\\xBF]' . '|\\xED[\\xA0-\\xBF][\\x80-\\xBF]/S', $replace, $altered);
}