i Have the following code, it works with single inputs but fails at compound outputs. The print array function confirms that the array values are correct. I don't know where the problem is.
Single Input:
1:10pm[Sat & Sun Only]
Compound Input:
10:35am, 12:40pm, 1:10pm[Sat & Sun Only]
Code excerpt is below:
function function1($input)
{
$key1 = ', ';
if (strpos($input, $key1) !== false) {
$commas = substr_count($input, $key1);
$arraySize = $commas + 1;
$result1 = explode($key1, $input);
} else {
$result1[0] = $input;
}
foreach ($result1 as $val) {
if (preg_match('/^\d{1,2}.\d{2}am\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found <br />";
} else if (preg_match('/^\d{1,2}.\d{2}pm\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found 2<br />";
} else if (preg_match('/^\d{1,2}.\d{2}am\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun)-(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found 3<br />";
} else if (preg_match('/^\d{1,2}.\d{2}pm\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun)-(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found 4<br />";
} else if (preg_match('/^\d{1,2}.\d{2}am\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun) & (?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found 5<br />";
} else if (preg_match('/^\d{1,2}.\d{2}pm\[(?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun) & (?:Mon|Tues|Wed|Thurs|Fri|Sat|Sun).Only\]$/', $input)) {
echo "Match was found 6<br />";
} else {
echo 'Not found ';
}
//print $val;
}
print_r($result1);
}
$imran = '10:35am, 12:40pm, 1:10pm[Sat & Sun Only]';
function1($imran);
function1
is a terrible name for a function. If you can't think of a good name for a function then that function is likely doing something very strange, or too many things. – Halcyon Apr 22 at 16:29