From 65a85c00663b9f9a597f04f1c2705e857ba50f38 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Fri, 6 Feb 2015 10:57:50 -0500 Subject: [PATCH] format_varname prepends _ instead of deleting numeric prefix, add format_slug --- format.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) { -- 1.7.10.4