473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

binary strrpos?

Hello,
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("mysite.com");

$needle = "blabla";

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

echo $x

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

Any ideas?

Feb 7 '06 #1
4 1073
giloosh wrote:
Hello,
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("mysite.com");

$needle = "blabla";

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

echo $x

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

Any ideas?

My *guess* would be that the Linux strrpos is counting the \r's whereas
the Windows one is not...

-david-

Feb 7 '06 #2
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
5.
again, this is only happening on the linux system, on windows it works
fine.

Feb 7 '06 #3
i solved the problem!
i used strpos instead of strrpos.
i have no idea why, but that made the difference.
thanks for the help

Feb 7 '06 #4
On 2006-02-07, giloosh <gi*******@gmail.com> wrote:
Hello,
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("mysite.com");

$needle = "blabla";

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

echo $x

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

Any ideas?


windows translates "\r\n" to "\n" when reading text files. If your mysite.com
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("mysite.com"));

Bye.
Jasen
Feb 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
20
by: Christian Stigen Larsen | last post by:
A signed int reserves one bit to signify whether a number is positive or negative. In light of this, a colleague asked me whether there existed an int in C++ that was -0, a zero with the negative...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
2
by: Lisa Pearlson | last post by:
Hi, My php application (on Apache/Linux) needs to do the following: The PHP script receives a request from a client (binary), asking for certain records of data. My PHP script loops through...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
by: John R. Delaney | last post by:
I am running in debugging mode after a clean C++ compilation under .NET 2003. In a BIG loop (controlled many levels up in the call stack), I open a file with fopen using the "a" option. Then I write...
10
by: rory | last post by:
I can't seem to append a string to the end of a binary file. I'm using the following code: fstream outFile("test.exe", ios::in | ios::out | ios::binary | ios::ate | ios::app)...
16
by: Erwin Moller | last post by:
Why is a binary file executable? Is any binary file executable? Is only binary file executable? Are all executable files binary? What is the connection between the attribute of binary and that of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.