定制 marc-mabe/entity-coder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marc-mabe/entity-coder

Composer 安装命令:

composer require marc-mabe/entity-coder

包简介

Encode & decode XML, HTML and own defined entities into different charsets

README 文档

README

!!! ARCHIVED !!!

THIS REPOSITORY HAS BEEN ARCHIVED WITHOUT ANY REPLACEMENT

Encode & decode XML, HTML and own defined entities into different charsets.

FEATURES

  • decode and encode hex entities
  • decode and encode decimal entities
  • convert from one charset to another
  • selectable if named entities will be used (on encode)
  • selectable if hex or decimal entities will be used (on encode)
  • selectable how to handle characters/entities which are not convertable to given output charset
  • selectable how to handle invalid characters
  • ACTIONS:
    • throw exception
    • call callback
    • ignore
    • substitute by a substitution character
    • use entity
    • translit by ASCII name

Usage

Encode

$entityCoder = new EntityCoder(array(
    // set named entity reference
    // -> 'special', 'xml', 'html' or an array of your own entities
    'entityReference' => 'special',

    // set your input charset (default: ISO-8859-1)
    'inputCharSet' => 'UTF-8',

    // set your output charset (default: ISO-8859-1)
    'outputCharSet' => 'ISO-8859-15',

    // convert to hex entities if no named entity exists (default: false)
    'hex' => true,
));

$text = $entityCoder->encode($text);

Decode

$entityCoder = new EntityCoder(array(
    // set named entity reference
    // -> 'special', 'xml', 'html' or an array of your own entities
    'entityReference' => 'html',

    // set your input charset (default: ISO-8859-1)
    'inputCharSet' => 'ISO-8859-15',

    // set your output charset (default: ISO-8859-1)
    'outputCharSet' => 'ASCII',

    // How to handle invalid characters
    // EXCEPTION  = throw an exception
    // CALLBACK   = call a callback
    // IGNORE     = replace by an empty character
    // SUBSTITUTE = substitute by an substitution character (default: "?")
    // TRANSLIT_* = convert to ASCII name with a fallback to one of the other actions
    'invalidCharAction' => EntityCoder::ACTION_SUBSTITUTE,

    // How to handle invalid entities
    // EXCEPTION  = throw an exception
    // CALLBACK   = call a callback
    // IGNORE     = replace by an empty character
    // SUBSTITUTE = substitute by an substitution character (default: "?")
    // ENTITY     = leave the entity as-is
    'invalidEntityAction' => EntityCoder::ACTION_ENTITY,
));

$text = $entityCoder->decode($text);

REQUIREMENTS

This library requires PHP 5.3.0 or later. Additionally the php extension iconv is needed. (enabled by default)

ISSUES AND FEEDBACK

If you find code in this release behaving in an unexpected manner or contrary to its documented behavior, please create an issue in the GitHub issue tracker at:

https://github.com/marc-mabe/entity-coder/issues

LICENSE

The files in this archive are released under the new BSD license. You can find a copy of this license in LICENSE.txt.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-06-03