mulertech/char-manipulation

此类用于字符操作

v1.0.2 2023-06-19 18:03 UTC

This package is auto-updated.

Last update: 2024-09-12 20:19:44 UTC


README

此类用于字符操作

安装

使用composer安装应用程序包有两种方法

将以下内容添加到您的 "composer.json" 文件的 require 部分

"mulertech/char-manipulation": "^1.0"

并运行以下命令

php composer.phar update

运行以下命令

php composer.phar require mulertech/char-manipulation "^1.0"

用法


specialCharsTrim:去除特殊字符并将它们转换为HTML实体
CharManipulation::specialCharsTrim(' Test trim ');

// 'Test trim'
CharManipulation::specialCharsTrim('<script\>Test without html balise</script>');

// 'Test without html balise'
CharManipulation::specialCharsTrim([' Test "trim"', '<script\>with</script>', ' array  ', ' and', 'null ', null]);

// ['Test &quot;trim&quot;', 'with', 'array', 'and', 'null', null]

specialCharsDecode:(通过引用解码字符到字符串或数组,不返回)
$test = '&#039;test single quote';
CharManipulation::specialCharsDecode($test);

// echo $test;
// "'test single quote";
$test = [
            'test1' => '&#039;test single quote',
            'test2' => 'test quote&quot;',
            'test3' => 'with null',
            'test4' => null,
            'test5' => [
                'test5a' => "&#039;test single quote",
                'test5b' => 'test quote&quot;',
                'test5c' => 'with null',
                'test5d' => null
            ]
        ];
CharManipulation::specialCharsDecode($test);

// echo $test;
// [
        'test1' => "'test single quote",
        'test2' => 'test quote"',
        'test3' => 'with null',
        'test4' => null,
        'test5' => [
            'test5a' => "'test single quote",
            'test5b' => 'test quote"',
            'test5c' => 'with null',
            'test5d' => null
        ]
   ];