From: Jason Woofenden Date: Fri, 6 Feb 2015 15:57:50 +0000 (-0500) Subject: format_varname prepends _ instead of deleting numeric prefix, add format_slug X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=65a85c00663b9f9a597f04f1c2705e857ba50f38 format_varname prepends _ instead of deleting numeric prefix, add format_slug --- 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) {