1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-13 16:53:59 +02:00

Merge pull request #70 from vlakoff/toAscii-2

Separate toAscii()'s charsArray to allow customization
This commit is contained in:
Daniel St. Jules
2015-01-13 12:25:16 -08:00

View File

@@ -426,7 +426,27 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function toAscii()
{
$str = $this->str;
$charsArray = array(
foreach ($this->charsArray() as $key => $value) {
$str = str_replace($value, $key, $str);
}
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
return static::create($str, $this->encoding);
}
/**
* Returns the replacements for the toAscii() method.
*
* @return array An array of replacements.
*/
protected function charsArray()
{
static $charsArray;
if (isset($charsArray)) return $charsArray;
return $charsArray = array(
'a' => array('à', 'á', 'â', 'ä', 'ã', 'ā', 'ą', 'ă', 'å', 'α',
'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ',
'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ',
@@ -515,14 +535,6 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
"\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A",
"\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"),
);
foreach ($charsArray as $key => $value) {
$str = str_replace($value, $key, $str);
}
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
return static::create($str, $this->encoding);
}
/**