Skip to content

Commit

Permalink
Merge pull request #36 from karptonite/whitespacebranch
Browse files Browse the repository at this point in the history
Convert and strip utf-8 spaces
  • Loading branch information
jbroadway committed Oct 15, 2015
2 parents 41b57e7 + afa8c38 commit bb9128c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions URLify.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public static function filter ($text, $length = 60, $language = "", $file_name =
$remove_pattern = ($file_name) ? '/[^_\-.\-a-zA-Z0-9\s]/u' : '/[^\s_\-a-zA-Z0-9]/u';
$text = preg_replace ($remove_pattern, '', $text); // remove unneeded chars
$text = str_replace ('_', ' ', $text); // treat underscores as spaces
$text = preg_replace ('/^\s+|\s+$/', '', $text); // trim leading/trailing spaces
$text = preg_replace ('/[-\s]+/', '-', $text); // convert spaces to hyphens
$text = preg_replace ('/^\s+|\s+$/u', '', $text); // trim leading/trailing spaces
$text = preg_replace ('/[-\s]+/u', '-', $text); // convert spaces to hyphens
$text = strtolower ($text); // convert to lowercase
return trim (substr ($text, 0, $length), '-'); // trim to first $length chars
}
Expand Down
2 changes: 2 additions & 0 deletions tests/URLifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function test_filter () {
$this->assertEquals ('aeoeueaeoeue', URLify::filter ('ÄÖÜäöü',60,"de"));

$this->assertEquals ('bobby-mcferrin-dont-worry-be-happy', URLify::filter ("Bobby McFerrin — Don't worry be happy",600,"en"));
// test stripping and conversion of UTF-8 spaces
$this->assertEquals ('test-mahito-mukai', URLify::filter('向井 真人test (Mahito Mukai)'));
}

function test_add_chars () {
Expand Down

0 comments on commit bb9128c

Please sign in to comment.