original_string: public static function validUtf8($text)
      {
          $text = strval($text);
  
          // First check for illegal surrogate pair sequences. See RFC 3629.
          if (preg_match('/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/S', $text)) {
              return false;
          }
  
          for ($i = 0, $len = strlen($text); $i < $len; ++$i) {
              $c = ord($text[$i]);
              if ($c > 128) {
                  if ($c > 247) {
                      // STD 63 (RFC 3629) eliminates 5 & 6-byte characters.
                      return false;
                  } elseif ($c > 239) {
                      $j = 3;
                  } elseif ($c > 223) {
                      $j = 2;
                  } elseif ($c > 191) {
                      $j = 1;
                  } else {
                      return false;
                  }
  
                  if (($i + $j) > $len) {
                      return false;
                  }
  
                  do {
                      $c = ord($text[++$i]);
                      if (($c < 128) || ($c > 191)) {
                          return false;
                      }
                  } while (--$j);
              }
          }
  
          return true;
      }
code: public static function validUtf8($text)
      {
          $text = strval($text);
  
          // First check for illegal surrogate pair sequences. See RFC 3629.
          if (preg_match('/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/S', $text)) {
              return false;
          }
  
          for ($i = 0, $len = strlen($text); $i < $len; ++$i) {
              $c = ord($text[$i]);
              if ($c > 128) {
                  if ($c > 247) {
                      // STD 63 (RFC 3629) eliminates 5 & 6-byte characters.
                      return false;
                  } elseif ($c > 239) {
                      $j = 3;
                  } elseif ($c > 223) {
                      $j = 2;
                  } elseif ($c > 191) {
                      $j = 1;
                  } else {
                      return false;
                  }
  
                  if (($i + $j) > $len) {
                      return false;
                  }
  
                  do {
                      $c = ord($text[++$i]);
                      if (($c < 128) || ($c > 191)) {
                          return false;
                      }
                  } while (--$j);
              }
          }
  
          return true;
      }
code_tokens: public static function validUtf8 ( $ text ) { $ text = strval ( $ text ) ; // First check for illegal surrogate pair sequences. See RFC 3629. if ( preg_match ( '/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/S' , $ text ) ) { return false ; } for ( $ i = 0 , $ len = strlen ( $ text ) ; $ i < $ len ; ++ $ i ) { $ c = ord ( $ text [ $ i ] ) ; if ( $ c > 128 ) { if ( $ c > 247 ) { // STD 63 (RFC 3629) eliminates 5 & 6-byte characters. return false ; } elseif ( $ c > 239 ) { $ j = 3 ; } elseif ( $ c > 223 ) { $ j = 2 ; } elseif ( $ c > 191 ) { $ j = 1 ; } else { return false ; } if ( ( $ i + $ j ) > $ len ) { return false ; } do { $ c = ord ( $ text [ ++ $ i ] ) ; if ( ( $ c < 128 ) || ( $ c > 191 ) ) { return false ; } } while ( -- $ j ) ; } } return true ; }
docstring: Check to see if a string is valid UTF-8.
  
  @param string $text  The text to check.
  
  @return boolean  True if valid UTF-8.
docstring_tokens: Check to see if a string is valid UTF - 8 .