me! wrote:X will be 3~6 long, is the main call sign
Y can be 1~3 long (optional)
Z is the prefix and can be 1 or 2 long (optional)
Then what I posted is not sufficient. It assumes that Z will be only one character long, but if it can be two ("kk/k9dog") then the code won't work.
Fortunately there's no way to be ambiguous with those rules:
1. The first part is either 3-6 X (X form) or 1-2 Z (Z/X form)
2. The second part is either 3-6 X (Z/X form) or 1-3 Y (X/Y form)
3. The third part is always 1-3 Y (Z/X/Y form)
and there is no string that will fit into multiple forms:
4. X form is 3-6
5. X/Y form is 3-6/1-3
6. Z/X form is 1-2/3-6
7. Z/X/Y form is 1-2/3-6/1-3
X will always be in the first position (X, X/Y) or second position (Z/X, Z/X/Y).
- If X then [0] will be 3-6 long
- If X/Y then [0] will be 3-6 long
- If Z/X then [0] will be 1-2 long
- If Z/X/Y then [0] will be 1-2 long
So
Code: Select all
if (strlen($parts[0]) >= 3) {
$value = $parts[0]; // X or X/Y
} else {
$value = $parts[1]; // Z/X or Z/X/Y
}
which is the same as before but >=3 instead of >1.
me! wrote:Only thing that would not do was pass just the value is no suffix or prefix was used. So I added this.
Appears to be working well.
If $callsign does not contain a slash then $parts will be an array of just $callsign.
explode("/", "k9dog") == array("k9dog")
That isset you have should not be necessary.