PHP code library

This is an extra subpage with various PHP codes, implemented as functions.

These functions were used to solve various problems in real web projects.
The solution for one problem may be implemented in many different ways (short, verbose, faster or nicer). We present own implementations, used in the past.

Function createPermalink() - how to create output for permalink from passed string:

The code

   * Generate permalink for input string. Function uses iconv.
   * @param string $str Input string
   * @return string
  public static function createPermalink($str)
    $output = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $output = preg_replace("/[^a-zA-Z0-9\/_| -]/", '', $output);
    $output = strtolower(trim($output, '-'));
    $output = preg_replace("/[\/_| -]+/", '-', $output); // final cleanup

    return $output;

Choose from currently available implementations:

This code library will be gradually supplemented. Probably we will create code library also for other languages (such as JavaScript, Python, Ruby).
Would you get more codes? Or maybe suggest further functions? Please use contact page: Contact