codeinc/utf8-sanitizer

Sanitize UTF-8 strings

1.3 2022-05-06 17:37 UTC

This package is auto-updated.

Last update: 2024-11-06 23:17:06 UTC


README

A simple UTF-8 sanitizer written in PHP 8 using iconv. This code is based after this StackOverflow response and the W3C UTF-8 verification recommended regular expression.

Usage

<?php

$sanitizer = new \CodeInc\Utf8Sanitizer\Utf8Sanitizer();

// validates a UTF-8 string
$sanitizer->isValidUtf8("A valid UTF-8 string."); // true

// sanitizes a string 
$validString = $sanitizer->sanitize("An invalid UTF-8 string.");

Installation

This library is available through Packagist and can be installed using Composer:

composer require codeinc/utf8-sanitizer

License

This library is published under the MIT license (see the LICENSE file).