jcadima
5/9/2017 - 5:29 PM

substr_compare

substr_compare


<?php

// c is the starting offset of "cdefg" goes to the end of string , c is less than d of "de"therefore  -1
echo substr_compare("abcdefg", "de", 2);  //  -1
echo "\n";


// l is the starting offset of "lcome" goes to the end of string, l is greater than c of "co" therefore  1+
echo substr_compare("welcome", "co", 2); // positive number
echo "\n";


// l is the starting offset of "lc" because second parameter was specified of length 2, l is greater than c of "co" therefore  1+
echo substr_compare("welcome", "co", 2,2); // positive number
echo "\n";


// c is the starting offset of "come" since it goes to the end of the string, no second parameter was specified, c of "come" is greater than c of "co" therefore 1+
echo substr_compare("weccome", "co", 3); // positive number
echo "\n";


// c is the starting offset of "co" since a second parameter was specified with length of 2, c of "co" is equal to c of "co" therefore 0
echo substr_compare("weccome", "co", 3,2); // 0
echo "\n";


// c is the starting offset, c is equal than c therefore  0
echo substr_compare("welcome", "co", 3,2); // positive number
echo "\n";