strlen

Is there a difference between $str == '' and strlen($str) == 0 in PHP?

As the title says: Is there a difference between $str == '' and strlen($str) == 0 in PHP? Is there any real speed difference and is one better to use than the other? ...

Parse PHP String Based On Number of Characters

Hello all, I'm starting to work on a small script that takes a string, counts the number of characters, then, based on the number of characters, splits/breaks the string apart and sends/emails 110 characters at a time. What would be the proper logic/PHP to use to: 1) Count the number of characters in the string 2) Preface each messag...

strlen() implementation in gcc

Can anyone point me to the definition of strlen() in GCC? I've been grepping release 4.4.2 for about a half hour now (while Googling like crazy) and I can't seem to find where strlen() is actually implemented. ...

Firefox displays incorrect value for php strlen function on variable

I have a variable that I am calculating the length of and in all browsers except FF (IE, Chrome, Safari) the value is 0. However in FF, the value is 65 (see screenshot - value beneath photograph) screenshot Link to site page I have cleared my cache with cc cleaner and using the clear cache option in FF itself. The code I am using wo...

Trouble using strlen method and another newbie question.

Here's my PHP code: <html> <Head> <?php $FirstName="Sergio"; $LastName="Tapia"; $firstNameCount=strlen($Firstname); ?> </Head> <body> <h1>It works!</h1> <?php echo("Why hello there Mr. "); echo $FirstName . " " . $LastName; ...

c++ , getting the length of an array using strlen in g++ compiler

could someone explain why i am getting this error when i am compiling the source using following g++ compiler #include <cstdio> #include <string> using namespace std; int main() { char source_language[50]; scanf("%16s\n",source_language); int length = sizeof(source_language); int sizeofchar = strlen(source_language)...

Assigning char value in one array to char value in another array

Sounds easy, but I've got a bug and I'm not sure what's causing it? nopunccount = 0; char *ra = new char[sizeof(npa)]; while (nopunccount <= strlen(npa)) { ra[nopunccount] = npa[strlen(npa) - nopunccount]; nopunccount++; } ra never gets a value into it and I have verified that npa has char values to provide within the nopunc...

How do I find the number of bytes within UTF-8 string with PHP?

I have the following function from the php.net site to determine the # of bytes in an ASCII and UTF-8 string: <?php /** * Count the number of bytes of a given string. * Input string is expected to be ASCII or UTF-8 encoded. * Warning: the function doesn't return the number of chars * in the string, but the number of bytes. * ...

PHP strlen question

Ok I am checking that a string is at least 4 characters long and 25 or less characters short I tried to use strlen like this $userNameSignupLength = strlen($userNameSignup); else if($userNameSignupLength<4 && $userNameSignupLength>25) { $userNameSignupError = "Must be between 4 to 25 characters long"; } but it ...

Quick strlen question

Hi again. I've come to bother you all with another probably really simple C question. Using the following code: int get_len(char *string){ printf("len: %lu\n", strlen(string)); return 0; } int main(){ char *x = "test"; char y[4] = {'t','e','s','t'}; get_len(x); // len: 4 get_len(y); // len: 6 return 0;...

My jQuery and PHP give different results on the same thing?

Hey all, Annoying brain numbing problem. I have two functions to check the length of a string (primarily, the js one truncates as well) heres the one in Javascript: $('textarea#itemdescription').keyup(function() { var charLength = $(this).val().length; // Displays count $('span#charCount').css({'color':'#666'}); $('sp...

C: sprintf leads to SIGSEGV core via an strlen

Hi, My C application has the following two lines: char buf[1024]; sprintf(buf, "%s/game/rabbit/habit/cmd/talkPipe", getenv("APPLICATION_PATH")); The application sporadically crashes with SIGSEGV in the following manner: strlen(ff2ba231, 0, ffbfe1d0, 10, 7fff24d7, 0)+0x50 sprintf(ffbfe2a4, ff2ba231, 0, 74656400, 12, ff362ef2)+0x24 Ra...

Is a strlen call in snprintf causing this segfault?

I have a void *, call if data which length I know, but is not terminated. I make a call like this snprintf(line, sizeof(line), "%*s", n, (const char*)data) where n is the known length. Almost always this works, but occasionally it results in a segfault. Whenever the segfault occurs, the back trace says the problem is inside strlen. ...

C strings, strlen and Valgrind

Hi everybody, I'm trying to understand why Valgrind is spitting out : ==3409== Invalid read of size 8 ==3409== at 0x4EA3B92: __GI_strlen (strlen.S:31) whenever I'm applying strlen on a dynamically allocated string? Here is a short testcase : #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *hello ...

PHP: get remote file size with strlen? (html)

I was looking at PHP docs for fsockopen and whatnot and they say you can't use filesize() on a remote file without doing some crazy things with ftell or something (not sure what they said exactly), but I had a good thought about how to do it: $file = file_get_contents("http://www.google.com"); $filesize = mb_strlen($file) / 1000; //KBs,...

strlen() Refuses to Read String from struct hostent * (SOLVED)

I've been working through a small tutorial on how to build a basic packet sniffer for Linux. I got everything working, and I now want to add IP-to-host mapping. Everything was working before I added this function: void IPtoHostname(char *ipaddress, char *hostname){ struct hostent *host; in_addr_t ip = inet_addr(ipaddress); ...

strlen() function

I have read that use of strlen is more expensive than such testing like this: We have a string x 100 characters long. I think that for (int i = 0; i < strlen(x); i++) is more expensive than this code: for (int i = 0; x[i] != '\0'; i++) Is it true? Maybe the second code will not work in some situation so is it better to use the fi...

Why is my Content-Length header wrong?

I am trying to find out the exact length of a string using strlen() in php 5.2. The string ($data) contains '\t' and '\n'. echo strlen($data); Code: // fetch table header $header = ''; while ($fieldData = $result->fetch_field()) { $header .= $fieldData->name . "\t"; } // fetch data each row, store...

STRLEN printf on two lines?

Hi, Can someone explain the following occurrence to me? unsigned int i; i = strlen("testData"); printf("%d\n", i); Output: 8 5 Why is it printing the extra 5? [Update:] After reading the comment, I stupidly realized where the 5 was coming from, sorry! ...