vgd/sanitize_string

有时你可能想清理包含外语字符的文件名或字符串;这个类可以帮助你完成这两项任务。

1.3 2020-08-03 16:02 UTC

This package is auto-updated.

Last update: 2024-09-06 02:20:15 UTC


README

Version Total Downloads Latest Unstable Version License

有时你可能想清理包含外语字符的文件名或字符串;这个类可以帮助你完成这两项任务。

使用方法

Install via composer:

composer require vgd/sanitize_string

or

require('SanitizeString.php');


The class uses two boolean parameters after the string/filename: 

The first one (isFileName) is used to tell the class that you are trying to clean a file name.

The second one (special) must be used if you would like to remove special characters as well from a 
string or a file name.

为了清理字符串

To remove foreign characters only:

echo SanitizeString::clean('Your string here');


To remove foreign AND special characters:

echo SanitizeString::clean('Your string here', false, true);

为了清理文件名

To remove foreign characters only:

SanitizeString::clean('Your filename here', true, false);


To remove foreign AND special characters:

SanitizeString::clean('Your filename here', true, true);


You can use absolute or relative paths for the file you want to rename.

最后注意

The main purpose of using associative arrays and not other techniques as regular 
expressions and preg_match etc. was to give the user the possibility of add or remove
characters depending of their needs.

Lets say that you have a spanish text and you want to remove all the characters but vowels 
with tilde and ñ characters; you can modify the arrays to achieve that.