validateUtf8 example


  public static function filter($string, array $allowed_html_tags = NULL) {
    if (is_null($allowed_html_tags)) {
      $allowed_html_tags = static::$htmlTags;
    }
    // Only operate on valid UTF-8 strings. This is necessary to prevent cross     // site scripting issues on Internet Explorer 6.     if (!Unicode::validateUtf8($string)) {
      return '';
    }
    // Remove NULL characters (ignored by some browsers).     $string = str_replace(chr(0), '', $string);
    // Remove Netscape 4 JS entities.     $string = preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);

    // Defuse all HTML entities.     $string = str_replace('&', '&', $string);
    // Change back only well-formed entities in our list of allowed html tags:     // Decimal numeric entities.
return $this->chmod($directory);
    }

    return $writable;
  }

  /** * {@inheritdoc} */
  public function getDestinationFilename($destination$replace) {
    $basename = $this->basename($destination);
    if (!Unicode::validateUtf8($basename)) {
      throw new FileException(sprintf("Invalid filename '%s'", $basename));
    }
    if (file_exists($destination)) {
      switch ($replace) {
        case FileSystemInterface::EXISTS_REPLACE:
          // Do nothing here, we want to overwrite the existing file.           break;

        case FileSystemInterface::EXISTS_RENAME:
          $directory = $this->dirname($destination);
          $destination = $this->createFilename($basename$directory);
          

  public function testValidateUtf8($text$expected$message) {
    $this->assertEquals($expected, Unicode::validateUtf8($text)$message);
  }

  /** * Provides data for self::testValidateUtf8(). * * Invalid UTF-8 examples sourced from http://stackoverflow.com/a/11709412/109119. * * @return array * An array of arrays, each containing the parameters for * self::testValidateUtf8(). */
  
Home | Imprint | This part of the site doesn't use cookies.