fix regex quoting and escaping

This commit is contained in:
Nathan Coad
2018-01-18 17:46:44 +11:00
parent dc7353e1e2
commit 0e427a8416

View File

@@ -38,24 +38,24 @@ function _booking_ucname($string) {
// captialize all first letters
//$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)));
$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_callback('/\\b($all_uppercase)\\b/', function ($m) { return strtoupper($m[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_callback('/\\b($all_lowercase)\\b/', function ($m) { return strtolower($m[1]); }, $string);
$string = preg_replace_callback("/\b($all_lowercase)\b/", function ($m) { return strtolower($m[1]); }, $string);
}
if ($prefixes) {
watchdog('booking_debug', "Checking prefixes");
preg_match("/\b($prefixes)(\w)/", $string, $matches);
watchdog('booking_debug', "<pre>Prefixes match test: \n@info</pre>", array('@info' => print_r( $matches, true)));
//watchdog('booking_debug', "Checking prefixes");
//preg_match("/\b($prefixes)(\w)/", $string, $matches);
//watchdog('booking_debug', "<pre>Prefixes match test: \n@info</pre>", array('@info' => print_r( $matches, true)));
// capitalize letter after certain name prefixes e.g 'Mc'
//$string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string);
$string = preg_replace_callback("/\b($prefixes)(\w)/", function ($m) {
@@ -66,7 +66,7 @@ function _booking_ucname($string) {
if ($suffixes) {
// decapitalize certain word suffixes e.g. 's
//$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);
$string = preg_replace_callback("/(\w)($suffixes)\b/", function ($m) { return $m[1] . strtolower($m[2]); }, $string);
}
/*