strpos: 2 results but 2 similar strings

108 Views Asked by At

I don't know what to do.

2 parameters: first:

0 D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival/php/checkSession.php(6): Phip/Engine/Login->checkSession() 1 D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival/login.php(3): include('D:/Google Drive...') {main}

second:

D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival/php/Phip/Engine/Login/Login.php

php function

private function clean( $clean ) {
    $clean = str_replace( '\\', '/', $clean );
    if ( !strpos( $clean, 'D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival' )) {
        return  str_replace( 'D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival', '', $clean );
    } 
}

Problem:

false: var_dump( !strpos( $param1, 'D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival' ) );

true: var_dump( !strpos( $param2, 'D:/Google Drive/Dokumente/Programmierung/Webentwicklung/htdocs/BeLL__Webseite_fuer_Filmfestival' ) );

I can't understand this, because this string is in both strings ... can someone help me please? Why is this not the same?

Thank you so much! I hope you unterstand what I want.

1

There are 1 best solutions below

1
On

You are using strpos() wrongly.

strpos() [finds] the numeric position of the first occurrence of needle in the haystack string.

And more importantly:

Warning: This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

So use it like:

strpos($needle, $haystack) === false // true if needle is not contained in haystack
strpos($needle, $haystack) !== false // true if needle is contained in haystack