Download the PHP package ducks-project/encoding-repair without Composer

On this page you can find all versions of the php package ducks-project/encoding-repair. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package encoding-repair

CharsetHelper

Github Action Status Coverage Status

Build Status Coverage codecov

Psalm Type Coverage Psalm Level

Latest Stable Version PHP Version Require

Total Downloads Monthly Downloads Daily Downloads

Duck's Validated Packagist online Documentation Status

Advanced charset encoding converter with Chain of Responsibility pattern, auto-detection, double-encoding repair, and JSON safety.

๐Ÿ†• What's New in v1.2

Type Interpreter System

New optimized type-specific processing with Strategy + Visitor pattern:

Batch Processing API

New optimized batch processing methods for high-performance array conversion:

Service-Based Architecture

CharsetHelper now uses a service-based architecture following SOLID principles:

PSR-16 Cache Support

Optional external cache integration for improved performance:

๐ŸŒŸ Why CharsetHelper?

Unlike existing libraries, CharsetHelper provides:

๐Ÿ“– Features

๐Ÿ“‹ Requirements

๐Ÿ“ฆ Installation

Optional Extensions (for better performance)

๐Ÿš€ Quick Start

๐Ÿ—๏ธ Usage

1. Basic Conversion

Convert between different character encodings:

Note: We use Windows-1252 instead of strict ISO-8859-1 by default because it includes common characters like โ‚ฌ, ล“, โ„ข which are missing in standard ISO.

Supported Encodings:

2. Automatic Encoding Detection

Let CharsetHelper detect the source encoding:

3. Batch Processing (New in v1.2)

Optimized for processing large arrays with single encoding detection:

4. Recursive Conversion (Arrays & Objects)

Convert nested data structures:

5. Double-Encoding Repair ๐Ÿ”ง

Fix strings that have been encoded multiple times (common with legacy databases):

How it works:

  1. Detects valid UTF-8 strings
  2. Attempts to reverse-convert (UTF-8 โ†’ source encoding)
  3. Repeats until no more layers found or max depth reached
  4. Returns the cleaned string

6. Safe JSON Operations

Prevent JSON encoding/decoding errors caused by invalid UTF-8:

7. Conversion Options

Fine-tune the conversion behavior:

Options explained:

๐ŸŽฏ Advanced Usage

Using CharsetProcessor Service (New in v1.1)

For better testability and flexibility, use the CharsetProcessor service directly:

Multiple Processor Instances

Dependency Injection

Custom Property Mappers (New in v1.2)

Optimize object processing by converting only specific properties:

Custom Type Interpreters (New in v1.2)

Add support for custom data types:

Registering Custom Transcoders

Extend CharsetHelper with your own conversion strategies using the TranscoderInterface:

Registering Custom Detectors

Add custom encoding detection methods using the DetectorInterface:

Chain of Responsibility Pattern

The class uses a Chain of Responsibility pattern for both detection and transcoding.

CharsetHelper uses multiple strategies with automatic fallback:

Transcoder priorities:

  1. UConverter (priority: 100, requires ext-intl): Best precision, supports many encodings
  2. iconv (priority: 50): Good performance, supports transliteration
  3. mbstring (priority: 10): Universal fallback, most permissive

Custom transcoders can be registered with any priority value. Higher values execute first.

Detector priorities:

  1. CachedDetector (priority: 200, wraps MbStringDetector): Caches detection results
  2. MbStringDetector (priority: 100, requires ext-mbstring): Fast and reliable using mb_detect_encoding
  3. FileInfoDetector (priority: 50, requires ext-fileinfo): Fallback using finfo class

Custom detectors can be registered with any priority value. Higher values execute first.

Cache Support (New in v1.2):

CachedDetector supports PSR-16 cache for persistent detection results:

๐Ÿ“Š Performance

Benchmarks on 10,000 conversions (PHP 8.2, i7-12700K):

Operation Time Memory
Simple UTF-8 conversion 45ms 2MB
Array (100 items) 180ms 5MB
Auto-detection + conversion 92ms 3MB
Double-encoding repair 125ms 4MB
Safe JSON encode 67ms 3MB
Batch conversion (1000 items) ~60% faster Same
Object with custom mapper (50 props) ~60% faster Same

Tips for performance:

๐Ÿ†š Comparison with Alternatives

Feature CharsetHelper ForceUTF8 Symfony String Portable UTF-8
Multiple fallback strategies โœ… โŒ โŒ โŒ
Extensible (CoR pattern) โœ… โŒ โŒ โŒ
Object recursion โœ… โŒ โŒ โŒ
Double-encoding repair โœ… โœ… โŒ โš ๏ธ
Safe JSON helpers โœ… โŒ โŒ โŒ
Multi-encoding support โœ… (7+) โš ๏ธ (2) โš ๏ธ โš ๏ธ (3)
Modern PHP (7.4+, strict types) โœ… โŒ โœ… โš ๏ธ
Zero dependencies โœ… โœ… โŒ โŒ

๐Ÿ” Use Cases

1. Database Migration (Latin1 โ†’ UTF-8)

2. CSV Import with Unknown Encoding

3. API Response Sanitization

4. Web Scraping

5. Legacy System Integration

๐Ÿงช Testing

๐Ÿ“š Glossary

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your changes
  4. Ensure tests pass (composer test)
  5. Run static analysis (composer analyse)
  6. Fix code style (composer cs-fix)
  7. Commit your changes (git commit -m 'Add amazing feature')
  8. Push to the branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

Development Setup

Code Quality Standards

๐Ÿ“„ License

This project is licensed under the MIT license see the LICENSE file for details.

๐Ÿ™ Credits

๐Ÿ”— Links

๐Ÿ’ฌ Support

โญ Star History

If this project helped you, please consider giving it a โญ on GitHub!


Made with โค๏ธ by the Duck Project Team


All versions of encoding-repair with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
ext-mbstring Version *
psr/simple-cache Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ducks-project/encoding-repair contains the following files

Loading the files please wait ...