If you use a regex, you're going to have to quotemeta one of the strings because '.' is a meta (regex command) character.
If you use substr, you'll have problems if the length of the part you are trying to match can vary. Ie. Could the strings be '13.2.3' & '13.2' for example.
Using index will allow you to avoid both these problems. You simple want to know if the shorter string matches the longer string at position 0:
$var1 = '1.1.2'; $var2 = '1.1'; if( index( $var1, $var2 ) == 0 ) { print "matches" } else { print "Doesn't match" }
In reply to Re: Regex question
by BrowserUk
in thread Regex question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |