X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=format.php;h=c913864d87c73c7c4c43086ce3eca6370ce12f2e;hp=e0818fdb401c4d732cec27ee21f9d6712ab27d1f;hb=15459c86d0996ab3037b1738a8be6efd378c1258;hpb=8a5f6e7c208344736b432515d9b93a1aa78790ed diff --git a/format.php b/format.php index e0818fd..c913864 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) { @@ -295,13 +302,13 @@ function format_dollars($str) { # date is edited as mm/dd/yyyy but stored as yyyy-mm-dd function format_mdy_to_ymd($str) { if($str == '') return ''; - require_once(__DIR__ . '/time.php'); + require_once(__DIR__.'/'.'time.php'); return mdy_to_ymd(format_oneline($str)); } # date is yyyy-mm-dd function format_ymd($str) { - require_once(__DIR__ . '/time.php'); + require_once(__DIR__.'/'.'time.php'); list($year, $month, $day) = ymd_clean($str); return sprintf('%04u-%02u-%02u', $year, $month, $day); }