neoncitylights/media-type
最新稳定版本:v3.1.0
Composer 安装命令:
composer require neoncitylights/media-type
包简介
Allows working with IANA media types as entities in PHP
README 文档
README
MediaType is a PHP library for parsing and serializing MIME types, also known as IANA media types.
This library is compliant to the WHATWG Mime Sniffing Standard.
Install
System requirements:
- Minimum PHP version: 8.2
intlPHP extension (installation instructions)
composer require neoncitylights/media-type
Usage
Parsing
<?php use Neoncitylights\MediaType\MediaType; use Neoncitylights\MediaType\MediaTypeParser; $parser = new MediaTypeParser(); $mediaType = $parser->parseOrNull( 'text/plain;charset=UTF-8' ); print( $mediaType->type ); // 'text' print( $mediaType->subType ); // 'plain' print( $mediaType->getEssence() ); // 'text/plain' print( $mediaType->getParameterValue( 'charset' ) ); // 'UTF-8'
Serializing
<?php use Neoncitylights\MediaType\MediaType; $mediaType1 = new MediaType( 'text', 'plain', [ 'charset' => 'UT-8' ] ); $mediaType1->toString(); // 'text/plain;charset=UTF-8' $mediaType2 = new MediaType( 'application', 'json', [] ); $mediaType2->toString(); // 'application/json'
Matching
<?php use Neoncitylights\MediaType\MediaType; use Neoncitylights\MediaType\MediaTypeParser; $parser = new MediaTypeParser(); $parser->parseOrNull( 'audio/midi' )->isAudioOrVideo(); // true $parser->parseOrNull( 'audio/ogg' )->isAudioOrVideo(); // true $parser->parseOrNull( 'application/ogg' )->isAudioOrVideo(); // true
License
This software is licensed under the MIT license (LICENSE-MIT or https://opensource.org/license/mit/).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.
统计信息
- 总下载量: 13.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-28