Skip to content

Instantly share code, notes, and snippets.

@felixprojekt
Created November 17, 2019 21:29
Show Gist options
  • Select an option

  • Save felixprojekt/09a3178b4ef7cfb95bd40b62c292e321 to your computer and use it in GitHub Desktop.

Select an option

Save felixprojekt/09a3178b4ef7cfb95bd40b62c292e321 to your computer and use it in GitHub Desktop.

Revisions

  1. felixprojekt revised this gist Nov 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-url-friendly-string.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <?php
    public function createSlug($string)
    public function createUrl($string)
    {
    $output = preg_replace('~[^\\pL0-9_]+~u', '-', $string);
    $output = trim($output, '-');
  2. felixprojekt renamed this gist Nov 17, 2019. 1 changed file with 0 additions and 0 deletions.
  3. felixprojekt created this gist Nov 17, 2019.
    11 changes: 11 additions & 0 deletions create-url-friendly-string
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?php
    public function createSlug($string)
    {
    $output = preg_replace('~[^\\pL0-9_]+~u', '-', $string);
    $output = trim($output, '-');
    $output = iconv('UTF-8', 'us-ascii//TRANSLIT', $output);
    $output = strtolower($output);
    $output = preg_replace('~[^-a-z0-9_]+~', '', $output);

    return $output;
    }