I have this string "test1.base-loc.com" which is the value inside the argument $baseURL. I'd like to get the "test1" using RegEx and compare the output to match to the given cases in my switch function. How can I do that properly?
private function getAppID($baseURL){
$re = '/(\w)*/m';
$str = $baseURL;
$to_return;
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE);
switch($matches[0]){
case 'test1':
$to_return = 2;
break;
case 'test2':
$to_return = 3;
break;
case 'test3':
$to_return = 4;
break;
case 'test4':
$to_return = 5;
break;
default:
$to_return = 1;
break;
}
return $to_return;
}