You could use regular expressions like so:
<?php
if(preg_match('/MH[0-9]+K/', 'MH123K')) {
echo "Match!";
}
This one allows for any random number.
Question
I have a program which create a random number with MH{random alphanumeric}K format.
eg : MHmnwfJHJ1234K
How to check if the random number is in this format?
Solution 2
You could use regular expressions like so:
<?php
if(preg_match('/MH[0-9]+K/', 'MH123K')) {
echo "Match!";
}
This one allows for any random number.
OTHER TIPS
Assume that you have your generated string(number) in $randNum variable. The simplest way would be this (but not the best way):
if($randNum[0]=="M" && $randNum[1]=="H" && $randNum[strlen($randNum)-1]=="K")
But the best way would be using regular expressions as @Allendar posted above me:
preg_match('/MH(\d+)K/', $subject, $matches)