clarkgrubb / hyperpolyglot

hyperpolyglot.org
Other
473 stars 94 forks source link

PHP prefix and suffix test #92

Open ghost opened 6 years ago

ghost commented 6 years ago

Currently PHP has nothing for the "prefix and suffix test":

http://hyperpolyglot.org/scripting#prefix-suffix-test

However you can do this with substr_compare:

http://php.net/substr-compare

Examples prefix:

$ php -r 'echo substr_compare("abcde", "ab", 0, 2);'
0
$ php -r 'echo substr_compare("abcde", "ac", 0, 2);'
-1

Examples suffix:

$ php -r 'echo substr_compare("abcde", "de", -2);'
0
$ php -r 'echo substr_compare("abcde", "df", -2);'
-1