Skip to content

Instantly share code, notes, and snippets.

@ihabunek
Last active May 8, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihabunek/1592dce1ae2081da2271bf875ac564ca to your computer and use it in GitHub Desktop.
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)
<?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