Last active
May 8, 2016 13:07
-
-
Save ihabunek/1592dce1ae2081da2271bf875ac564ca to your computer and use it in GitHub Desktop.
A use case for the pipe operator in PHP (https://wiki.php.net/rfc/pipe-operator)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function slugify($string) | |
{ | |
$string = strtr($string, CharacterMap::get()); | |
$string = preg_replace('/[^\\p{L}\\d]+/u', '-', $string); | |
$string = trim($string, '-'); | |
$string = iconv('utf-8', 'ASCII//TRANSLIT', $string); | |
$string = strtolower($string); | |
$string = preg_replace('/[^-\w]+/', '', $string); | |
return $string; | |
} | |
function slugify($string) | |
{ | |
return strtr($string, CharacterMap::get()) | |
|> preg_replace('/[^\\p{L}\\d]+/u', '-', $$) | |
|> trim($$, '-') | |
|> iconv('utf-8', 'ASCII//TRANSLIT', $$) | |
|> strtolower($$) | |
|> preg_replace('/[^-\w]+/', '', $$); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment