PHP code example of zyan / detect-unicode-charset

1. Go to this page and download the library: Download zyan/detect-unicode-charset library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zyan / detect-unicode-charset example snippets



use Zyan\DetectUnicodeCharset\DetectUnicodeCharset;

$detectUnicodeCharset = new DetectUnicodeCharset();


$res = $detectUnicodeCharset->charset('中文');
//return ['Han']

$res = $detectUnicodeCharset->charset('こんにちは');
//return ['Hiragana']

//命中多个时 返回多个
$res = $detectUnicodeCharset->charset('中文こんにちは');
//return ['Hiragana','Han'];



$detectUnicodeCharset = new DetectUnicodeCharset();

$detectUnicodeCharset->charset('测试こんにちは',['Han','Hiragana']);



$detectUnicodeCharset = new DetectUnicodeCharset();

//在默认中追加
$detectUnicodeCharset->addCharset(['Han','Hiragana']);

//重置 默认配置将被复盖
$detectUnicodeCharset->setCharset(['Han','Hiragana']);

//test
$detectUnicodeCharset->charset('测试こんにちは',['Han','Hiragana']);



$detectUnicodeCharset = new DetectUnicodeCharset();


$detectUnicodeCharset->charset('这是中文吗?','Han');
// return true

$detectUnicodeCharset->charset('what is your name?','Han');
// return false