DoctorTestCase::inStr PHP Method

inStr() public method

Can be set to ignore insignificant whitespace in HTML output. Any whitespace in $expected is then allowed to be expanded in $string. If you want to capture whitespace in $string which may also be completely absent, use a pipe in $expected (e.g. '|A cell|'). If $expected happens to contain a literal pipe, escape it with another pipe ('||'). (Quick and dirty solution for pipe escaping. Will get off track if the needle contains a chr(1) - which is rather unlikely.)
public inStr ( string $haystack, string $needle, boolean $ignoreInsigificantWhitespace = false ) : boolean
$haystack string the haystack
$needle string the needle (oh, really?!)
$ignoreInsigificantWhitespace boolean allows for additional space, tab and newline chars
return boolean
    function inStr($haystack, $needle, $ignoreInsigificantWhitespace = false)
    {
        if ($ignoreInsigificantWhitespace) {
            $needle = preg_quote($needle, '/');
            $needle = str_replace('\\|\\|', chr(1), $needle);
            $needle = preg_replace('%\\\\\\|\\s+%', ' ', $needle);
            $needle = preg_replace('%\\s+\\\\\\|%', ' ', $needle);
            $needle = str_replace('\\|', '\\s*', $needle);
            $needle = str_replace(chr(1), '\\|', $needle);
            $needle = preg_replace('/\\s+/', '\\s+', $needle);
            $contained = (bool) preg_match("/{$needle}/", $haystack);
        } else {
            $contained = strpos($haystack, $needle) !== false;
        }
        return $contained;
    }