Skip to content

codeinchq/utf8-sanitizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UTF-8 sanitizer

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).