Skip to content

Commit

Permalink
Merge pull request #1 from codeinchq/v1.1.0
Browse files Browse the repository at this point in the history
V1.1.0
  • Loading branch information
joanfabregat authored Jul 17, 2020
2 parents e3dbadf + bc5b39c commit 42bdff7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ echo StripAccents::strip("C'est une super chaîne de caractères avec beaucoup d
echo StripAccents::strip("ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ");
// echoes: AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy

echo StripAccents::stripNonPrint("ABC ÀÈÝ 是我这");
// echoes: ABC AEY ---

// You can specify any encoding supported by htmlentities() as a second parameter
echo StripAccents::strip("A strïng with àccénts", "iso-8859-1");
```
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeinc/strip-accents",
"version": "1.0.0",
"version": "1.1.0",
"description": "Removes accents from strings",
"homepage": "https://github.com/CodeIncHQ/StripAccents",
"type": "library",
Expand All @@ -24,8 +24,8 @@
"authors": [
{
"name": "Joan Fabrégat",
"email": "joan@codeinc.fr",
"homepage": "https://www.codeinc.fr",
"email": "joan@codeinc.co",
"homepage": "https://www.codeinc.co",
"role": "developer"
}
],
Expand Down
15 changes: 14 additions & 1 deletion src/StripAccents.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StripAccents
* @param string $encoding
* @return string
*/
public static function strip(string $string, $encoding = self::DEFAULT_ENCODING):string
public static function strip(string $string, string $encoding = self::DEFAULT_ENCODING): string
{
// converting accents in HTML entities
$string = htmlentities($string, ENT_NOQUOTES, $encoding);
Expand All @@ -61,4 +61,17 @@ public static function strip(string $string, $encoding = self::DEFAULT_ENCODING)

return $string;
}

/**
* @param string $string
* @param string $encoding
* @param string $replaceWith
* @return string
*/
public static function stripNonPrint(string $string,
string $replaceWith = '',
string $encoding = self::DEFAULT_ENCODING): string
{
return preg_replace('/[[:^print:]]/', $replaceWith, self::strip($string, $encoding));
}
}

0 comments on commit 42bdff7

Please sign in to comment.