X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=format.php;h=28c555daedb7dae0c89ea9cfcb59ca28c8182a4a;hp=e0818fdb401c4d732cec27ee21f9d6712ab27d1f;hb=65a85c00663b9f9a597f04f1c2705e857ba50f38;hpb=8d6b4ad8d1273c63c348c2de2bbb1afe439bd94c diff --git a/format.php b/format.php index e0818fd..28c555d 100644 --- a/format.php +++ b/format.php @@ -163,11 +163,18 @@ function format_image_w_h_thumb_w_h($str) { return "$filename $width $height $thumb_filename $thumb_width $thumb_height"; } +function format_slug($str) { + $str = strtolower($str); + $str = str_replace("'", '', $str); + $str = preg_replace('/[^a-z0-9-]+/', '-', $str); + return trim($str, '-'); +} + function format_varname($str) { $str = preg_replace("/([a-z])([A-Z])/", "\\1_\\2", $str); # split words on camelCase $str = strtolower($str); - $str = ereg_replace('[^a-z0-9_]', '_', $str); - return ereg_replace('^[0-9]*', '', $str); + $str = preg_replace('/[^a-z0-9_]+/', '_', $str); + return preg_replace('/^([^a-z_])/', "_\\1", $str); } function format_oneline($str) {