Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ea8b6e7b
Commit
ea8b6e7b
authored
May 30, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhance Inflector helper with ascii function
parent
c8df8e2a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
Inflector.php
framework/yii/helpers/base/Inflector.php
+15
-0
InflectorTest.php
tests/unit/framework/helpers/InflectorTest.php
+16
-0
No files found.
framework/yii/helpers/base/Inflector.php
View file @
ea8b6e7b
...
...
@@ -475,4 +475,19 @@ class Inflector
default
:
return
$number
.
'th'
;
}
}
/**+
* Converts all special characters to the closest ascii character equivalent.
* @param string $string the string to be converted.
* @param array $replace the characters to be replaced by spaces.
* @return string the translated
*/
public
static
function
ascii
(
$string
,
$replace
=
array
())
{
if
(
!
empty
(
$replace
))
{
$string
=
str_replace
((
array
)
$replace
,
' '
,
$string
);
}
$string
=
iconv
(
'UTF-8'
,
'ASCII//TRANSLIT'
,
$string
);
return
preg_replace
(
"/[^a-zA-Z0-9\/_|+ -]/"
,
''
,
$string
);
}
}
tests/unit/framework/helpers/InflectorTest.php
View file @
ea8b6e7b
...
...
@@ -132,4 +132,20 @@ class InflectorTest extends TestCase
{
$this
->
assertEquals
(
'21st'
,
Inflector
::
ordinalize
(
'21'
));
}
public
function
testAscii
()
{
$this
->
assertEquals
(
"AAAAAAAECEEEEIIIIDNOOOOOUUUUYssaaaaaaaeceeeeiiiidnooooouuuuyy"
,
Inflector
::
ascii
(
'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ'
));
$this
->
assertEquals
(
"Messd up --text-- just to stress /test/ our little clean url function--"
,
Inflector
::
ascii
(
"Mess'd up --text-- just (to) stress /test/ ?our! `little`
\\
clean
\\
url fun.ction!?-->"
));
$this
->
assertEquals
(
"Perche l erba e verde"
,
Inflector
::
ascii
(
"Perché l'erba è verde?"
,
"'"
));
$this
->
assertEquals
(
"Peux-tu m aider s il te plait"
,
Inflector
::
ascii
(
"Peux-tu m'aider s'il te plaît?"
,
"'"
));
$this
->
assertEquals
(
"Tank-efter-nu-forrn-vi-foser-dig-bort"
,
Inflector
::
slug
(
Inflector
::
ascii
(
"Tänk efter nu – förr'n vi föser dig bort"
)));
$this
->
assertEquals
(
"Custom delimiter example"
,
Inflector
::
ascii
(
"Custom`delimiter*example"
,
array
(
'*'
,
'`'
)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment