defining the negative start parameter in substr as a variable
Is using the following correct for defining the negative start parameter for a substr, because its the only way i know how to get it to retur the correct result.
$start == (-44);
or
$start == (int) -44;
$pair = substr($s开发者_高级运维tr, $start, 4);
the substr
call is valid, the only error in your code (posted here) is the ==
operator.
It should be:
$start = -44;
$pair = substr($str, $start, 4)
Also is the start value -44
the 44th character from start or the end. The above code considers -44
to mean 44th character from end of string.
One more error you could run into is if the length of $str
is less than 44.
You can just add a -
before an expression (including a variable) to invert its sign:
$pair = substr($str, -$start, 4);
Or
$pair = substr($str, -44, 4);
精彩评论