From c29d8a7a2174ecaeed9b1d1cd13623abcbd06c1c Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 18 Jan 2018 17:37:35 +1100 Subject: [PATCH] update to use preg_replace_callback --- booking.helper.inc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/booking.helper.inc b/booking.helper.inc index 83acfd1..3530a22 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -37,25 +37,30 @@ function _booking_ucname($string) { $suffixes = "'S"; // captialize all first letters - $string = preg_replace('/\\b(\\w)/e', 'strtoupper("$1")', strtolower(trim($string))); + //$string = preg_replace('/\\b(\\w)/e', 'strtoupper("$1")', strtolower(trim($string))); + $string = preg_replace_callback('/\\b(\\w)/', function ($m) { return strtoupper($m[1]); }, strtolower(trim($string))); if ($all_uppercase) { // capitalize acronymns and initialisms e.g. PHP - $string = preg_replace("/\\b($all_uppercase)\\b/e", 'strtoupper("$1")', $string); + //$string = preg_replace("/\\b($all_uppercase)\\b/e", 'strtoupper("$1")', $string); + $string = preg_replace_callback('/\\b($all_uppercase)\\b/', function ($m) { return strtoupper($m[1]); }, $string); } if ($all_lowercase) { // decapitalize short words e.g. and // all occurences will be changed to lowercase - $string = preg_replace("/\\b($all_lowercase)\\b/e", 'strtolower("$1")', $string); + //$string = preg_replace("/\\b($all_lowercase)\\b/e", 'strtolower("$1")', $string); + $string = preg_replace_callback('/\\b($all_lowercase)\\b/', function ($m) { return strtolower($m[1]); }, $string); } if ($prefixes) { // capitalize letter after certain name prefixes e.g 'Mc' - $string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string); + //$string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string); + $string = preg_replace_callback('/\\b($prefixes)(\\w)/', function ($m) { return $m[1] . strtoupper($m[2]); }, $string); } if ($suffixes) { // decapitalize certain word suffixes e.g. 's - $string = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")', $string); + //$string = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")', $string); + $string = preg_replace_callback('/(\\w)($suffixes)\\b/', function ($m) { return $m[1] . strtolower($m[2]); }, $string); } /*