Hi
strlen does not return the correct value .I compared the filesize()
and strlen byte size but they are not equal. I must find binary string
length and it must be equal to filesize()
thks. 5 28479
gezerpunta wrote:
strlen does not return the correct value .I compared the filesize()
and strlen byte size but they are not equal. I must find binary string
length and it must be equal to filesize()
Then use filesize(). D'oh!
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
On May 28, 10:40 am, gezerpunta <css...@gmail.c omwrote:
Hi
strlen does not return the correct value .I compared the filesize()
and strlen byte size but they are not equal. I must find binary string
length and it must be equal to filesize()
thks.
http://us.php.net/manual/en/function...rlen.php#72979
Google searches ("php binary string length") come in handy...
On May 28, 6:02 pm, "farri...@gmail .com" <farri...@gmail .comwrote:
On May 28, 10:40 am, gezerpunta <css...@gmail.c omwrote:
Hi
strlen does not return the correct value .I compared the filesize()
and strlen byte size but they are not equal. I must find binary string
length and it must be equal to filesize()
thks.
http://us.php.net/manual/en/function...rlen.php#72979
Google searches ("php binary string length") come in handy...
In PHP, like in C, the string ends with a zero-character, '\0', (char)
0, null-terminator, null-byte or whatever you like to call it. Thus,
if you have binary strings, they probably have this character
somewhere inside them, although that doesn't mean it's the end of the
string. From this reason, it's not very smart to use ordinary
strlen(), and str* functions in general, for binary data. Use, as
farrishj suggested, mb-strlen (multibyte string), or use filesize()
directly, as Ortega suggested. You can, however, make your own
functions to take care of this, just remember the number of bytes you
read together with the data - this, of course, if aforementioned
functions are not good enough for you.
On 28 May 2007 09:29:46 -0700, Darko <da************ **@gmail.comwro te:
>On May 28, 6:02 pm, "farri...@gmail .com" <farri...@gmail .comwrote:
>On May 28, 10:40 am, gezerpunta <css...@gmail.c omwrote:
strlen does not return the correct value .I compared the filesize()
and strlen byte size but they are not equal. I must find binary string
length and it must be equal to filesize()
http://us.php.net/manual/en/function...rlen.php#72979
Google searches ("php binary string length") come in handy...
In PHP, like in C, the string ends with a zero-character, '\0', (char) 0, null-terminator, null-byte or whatever you like to call it.
No, that's not the case - PHP strings are stored with both the length and the
data, unlike C strings that just has one pointer and uses a terminator. They're
"binary-safe" - NUL doesn't terminate the string.
See the definition of zvalue_value in zend.h; the string part has both a "char
*val" and "int len".
Problems would start if you're using the mbstring.func_o verload, which changes
how strlen() and the other functions work, and does try and treat strings as
strings of characters in a specific encoding rather than a string of bytes.
This is not the normal PHP behaviour.
$ cat test.php
<?php
$x = chr(0) . chr(0) . "blah" . chr(0) . chr(0);
print strlen($x);
?>
$ php test.php
8
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Andy Hassall wrote:
No, that's not the case - PHP strings are stored with both the length and the
data, unlike C strings that just has one pointer and uses a terminator. They're
"binary-safe" - NUL doesn't terminate the string. [snip]
Andy is correct. By default, PHP strings are treated like binary
strings, which works great for 8-bit encodings but not so much for UTF-8
or other multibyte character encodings. mbstring tries to "fix" this
using the automatic string overload, but then you lose the ability to
process binary data.
- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.o rg Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGWytBqTO +fYacSNoRAgcBAJ 9FrhQ62Z6HVRFBg OKwiXIiciAZjACf XhL4
A9uNj8G02gyQOOp p1Q/vVhs=
=xbaE
-----END PGP SIGNATURE----- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johannes |
last post by:
Hi,
I tried to pack eight integer values and one string into one binary
string, which I would like to store in a mysql db.
I encountered two problems doing this:
1)
$this->packed = pack('N8A*', $this->value1, $this->value2,
$this->value3, $this->value4, $this->value5, $this->value6,
$this->value7, $this->value8, $this->stringvalue);
|
by: Dan Jones |
last post by:
Hello,
I'm trying to figure out how to get bit operators to work on a binary
string. This is what I'm trying to do:
list(frame) #where frame is a binary string
y = frame << 8
It gives me a TypeError. Whats the best way to get around that? I think
the struct module may be what I'm looking for, if so could someone give
|
by: sathyashrayan |
last post by:
Group,
I have some doubts in the following program.
------------------program---------------------
/*
** Make an ascii binary string into an integer.
*/
#include <string.h>
unsigned int bstr_i(char *cptr)
|
by: Tarun |
last post by:
Hi All,
I need to find a particular substring in a binary string(some text
appended & prepended to binary data).
I cant use strstr since it terminates on receiving '\0'which can be
there in binary data also I cant use memmem. Is there any other
available function to do this.
Regards
Tarun
|
by: jt |
last post by:
I'm needing to take a binary string start at a certain position and return a
pointer from that postion to the end of the binary stirng.
something like this:
char bstr;
char *pos;
pos=mid(bstr,35); / *return a pointer of the rest of the binary string
starting at element 35 */
| |
by: Bammer22 |
last post by:
I am trying to BinaryWrite an image from a binary string that I am storing in the web.config file. The image is just a 1x1 pixel gif. I am setting the content type to "image/gif", but the output is just my string. Any suggestions? Code is below
byte bytes = Encoding.UTF8.GetBytes(ConfigurationSettings.AppSettings.ToString())
httpContext.Response.ContentType = "image/gif";
httpContext.Response.BinaryWrite(bytes)
|
by: elliotng.ee |
last post by:
I have a text file that contains a header 32-bit binary. For example,
the text file could be:
%%This is the input text
%%test.txt
Date: Tue Dec 26 14:03:35 2006
00000000000000001111111111111111
11111111111111111111111111111111
00000000000000000000000000000000
11111111111111110000000000000000
|
by: andrew.douglas11 |
last post by:
Hello,
I'm looking to display an image in the browser using a binary string
containing all the bytes that make up a GIF image. I've tried all
the standard encodings in System.Text.Encoding, but the images aren't
showing up. I'm using the approach where I'm setting ImageURL =
"GetImage.aspx?id=1". Here's my code from GetImage.aspx:
Dim imageData As String = the binary data representing a .gif file
Dim imageBytes() As Byte =
|
by: Andrew Lentvorski |
last post by:
Basically, I'd like to use the ctypes module as a much more descriptive
"struct" module.
Is there a way to take a ctypes.Structure-based class and convert it
to/from a binary string?
Thanks,
-a
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |