neoncitylights/media-type 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

neoncitylights/media-type

最新稳定版本:v3.1.0

Composer 安装命令:

composer require neoncitylights/media-type

包简介

Allows working with IANA media types as entities in PHP

README 文档

README

Packagist version License Docs CI Code coverage

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:

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.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04