Changeset 486


Ignore:
Timestamp:
Aug 18, 2014 10:20:21 AM (10 years ago)
Author:
anonymous
Message:

Added URLSlug function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r485 r486  
    398398        return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
    399399    }
     400}
     401
     402/*
     403* Converts a string into a URL-safe slug, removing spaces and non word characters.
     404*
     405* @access   public
     406* @param    string  $str    String to convert.
     407* @return   string          URL-safe slug.
     408* @author   Quinn Comendant <quinn@strangecode.com>
     409* @version  1.0
     410* @since    18 Aug 2014 12:54:29
     411*/
     412function URLSlug($str)
     413{
     414    $slug = preg_replace(array('/[^\w]+/', '/^-+|-+$/'), array('-', ''), $str);
     415    $slug = strtolower($slug);
     416    return $slug;
    400417}
    401418
Note: See TracChangeset for help on using the changeset viewer.