Re: Is "strpos(...)" safe to use on binary data?
| From: | Rasmus Lerdorf | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: Is "strpos(...)" safe to use on binary data? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145341@lists.php.net to get a copy of this message | ||
strpos() uses our own php_memnstr() function to search a string. It's an
inlined function that looks like this:
static inline char *
php_memnstr(char *haystack, char *needle, int needle_len, char *end)
{
char *p = haystack;
char ne = needle[needle_len-1];
end -= needle_len;
while (p <= end) {
if ((p = memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
if (!memcmp(needle, p, needle_len-1)) {
return p;
}
}
if (p == NULL) {
return NULL;
}
p++;
}
return NULL;
}
You didn't specify which operating system you were on, but both memchr()
and memcmp() damn well better be binary-safe on your OS or you are going
to have some nasty problems. Your problem is likely elsewhere in your
script.
By the way, you also didn't specify your PHP version. In really early PHP
4 beta releases strpos() was not binary safe.
-Rasmus
On Fri, 25 Apr 2003, Ken Tozier wrote:
> I'm trying to extract some Photoshop info from jpeg files by looking
> for specific xml markers and "strpos" doesn't seem to be able to find
> strings that I know for a fact are in my test file. Does "strpos" do
> some sort of character conversion in the background to make whatever
> it is passed officially a "string"?
>
> Thanks,
>
> Ken
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>