Backport #2987: Fix boundary cases of strspn, strcspn and substr_replace

I'm all for refactoring, but a precondition for refactoring is that the
original copies of the code in some way resemble each other. While the
bounds checks for strspn, substr_replace and substr might look
superficially similar, in fact they can't be merged with a single
simple if(strict) to take care of the divergence. The main problem is
that multi-pass normalization of the inputs gives you some interesting
and arguably broken behaviour when there are multiple issues that need
to be simultaneously fixed.

So, unrefactor (expand?) string_substr_check() into its three
consistutent parts, with code in the two new parts based closely on the
Zend source in the current git master. Remove the "strict" parameter,
now implicitly true.

Added a test case which previously failed in multiple ways. In
particular, strspn('','x') returned the wrong thing, which broke the
MediaWiki parser quite badly. The expect file was generated by PHP 5.5
and is identical to the one generated by PHP 5.3.

Submitted on behalf of a third-party: The PHP Group
Source: PHP 5.6.0-dev
License: version 3.01 of the PHP license