top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In PHP strlen is returning +1 more than it should

0 votes
424 views

Trying to manage line breaks in some output I'm generating and using strlen to measure the lengths of the strings I'm printing. Discovered something strange (to me!) in that strlen is returning +1 more than it
should.

The strings are from a query of my database - simple name fields. But everyone of them is coming back with a length that is one more than I see.

posted Jul 5, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Doesn't work for me.

php > var_dump("Mike Hall", strlen("Mike Hall"));
string(9) "Mike Hall"
int(9)

Try trimming it first and then apply strlen.

answer Jul 5, 2013 by anonymous
Why would I need to trim something that I can already see doesn't have  any trailing or leading characters?
Because there are characters you can't see?
Similar Questions
+1 vote

I have a code in PHP something like this

 if (strlen($profile['current-employer']) == 0)
     break;
 else
     return a;

Now in some cases $profile['current-employer'] can be non-existent, now here my question is in the case of non-existent variable what strlen will result... (This is related with QueryHome code)

+2 votes

I wrote a script, but when searched brings only one set of results. How do I make it so if there is more than one result, it will display them all?

+1 vote

What are the perceived advantages of one over other while deciding to choose the Web development technology, considering all aspects right from design to hosting.

...