binary strrpos?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am having trouble getting the strrpos from a file on a linux machine.

someone says it has something to do with binary?
The code works fine on windows, but when i run it on a linux server it
gives me a different result

heres an examples:
$haystack= file_get_contents("");

$needle = "blabla";

$x = strrpos($haystack, $needle);

echo $x

//$x returns 201 on windows
//$x returns 300 on linux

Any ideas?

Re: binary strrpos?

giloosh wrote:
Quoted text here. Click to load it
My *guess* would be that the Linux strrpos is counting the \r's whereas  
the Windows one is not...


Re: binary strrpos?

i stripped all of the \n's , \r's , \nr's \rns' and spaces out of it.
its not even finding the string that i am searching for, as if it does
not even understand my string. its returning something else completely
for example if i search for the position of "l" in apple it will return
again, this is only happening on the linux system, on windows it works

Re: binary strrpos?

i solved the problem!
i used strpos instead of strrpos.
i have no idea why, but that made the difference.
thanks for the help

Re: binary strrpos?

Quoted text here. Click to load it

windows translates "\r\n" to "\n" when reading text files. If your
file (bad name for a text file on windows) has 99 (very short) lines before  
the last occurrance of "blabla" that would explain it.

easiest fix:

$haystack= preg_replace("/\r\n/","\n",file_get_contents(""));

Site Timeline