I have a string (product sku): TC00111009
(as example, it can be TTIIIIIII (T=Text,I=Integer)
)
How I can check that 4th position's TC00[1]11009
value is 1
or 2
? Which php functions will fit for this?
I have a string (product sku): TC00111009
(as example, it can be TTIIIIIII (T=Text,I=Integer)
)
How I can check that 4th position's TC00[1]11009
value is 1
or 2
? Which php functions will fit for this?
You'll be interested in PHP's substr()
function:
$value = substr($string, 3, 1);
if (($value == 1) || ($value == 2)) {
// it's equal to 1 or 2
} else {
// something else
}
You can also use direct string-index accessing (i.e. treating the string like an array):
$value = $string[3];
If you take this approach, make sure your string is long enough first: if (strlen($string) > 4)