Re: [PHP] strlen ?

2013-07-11 Thread Caio Tavares
Try with mb_strlen

see
http://www.php.net/manual/en/function.mb-strlen.php


2013/7/5 Jim Giner 

> 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.
>
> Ex.
>
> Mike Hall  comes back as 10, not 9
> F.B. comes back as 5, not 4.
>
> I've looked at my data and counted the chars - there is no extra space at
> the beginning or end in my table.
>
> Anyone have an explanation?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] strlen ?

2013-07-06 Thread Lester Caine

Jim Giner wrote:

It's probably worth checking the sting length back through your code
just to confirm what added it?


The best I can figure is that I did a preload of many of the names from a csv
file.  Apparently when I do that it stores the LF at the end of the csv line.
Have to remember that the next time.


AH - I use that to flag the end of line when I pulled the data apart - so it 
gets stripped ;)
Then I found fgetcsv() which replaced the manual code and gave just the data as 
an array.


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-06 Thread Jim Giner

On 7/6/2013 2:59 AM, Lester Caine wrote:

Jim Giner wrote:

And the answer is - yes, there is a LF char at the end of my data in
my whole
table.

Now the question is - how the heck did I put that in there?  Certainly
not
intentionally.  The data is captured from a d/e screen I wrote and it
simply
grabs the post value and inserts a new record with that value along
with some
other values.  And I don't see anything concatenating a LF to my string.


The obvious question that comes to mind is 'What OS'? Having seen this
sort of niggle many times I tend to find it relates to something working
'cross-os' a bit like windows ignoring case in file name and linux then
complaining it can't find a file.

It's probably worth checking the sting length back through your code
just to confirm what added it?

The best I can figure is that I did a preload of many of the names from 
a csv file.  Apparently when I do that it stores the LF at the end of 
the csv line.  Have to remember that the next time.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Lester Caine

Jim Giner wrote:

And the answer is - yes, there is a LF char at the end of my data in my whole
table.

Now the question is - how the heck did I put that in there?  Certainly not
intentionally.  The data is captured from a d/e screen I wrote and it simply
grabs the post value and inserts a new record with that value along with some
other values.  And I don't see anything concatenating a LF to my string.


The obvious question that comes to mind is 'What OS'? Having seen this sort of 
niggle many times I tend to find it relates to something working 'cross-os' a 
bit like windows ignoring case in file name and linux then complaining it can't 
find a file.


It's probably worth checking the sting length back through your code just to 
confirm what added it?


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Ashley Sheridan


Jim Giner  wrote:

>On 7/5/2013 3:02 PM, Stephen wrote:
>> On 13-07-05 02:50 PM, Jim Giner wrote:
>>>
>>> Now the question is - how the heck did I put that in there?
>Certainly
>>> not intentionally.  The data is captured from a d/e screen I wrote
>and
>>> it simply grabs the post value and inserts a new record with that
>>> value along with some other values.  And I don't see anything
>>> concatenating a LF to my string.
>>>
>> Is this a browser being used for input? Never assume what a browser
>will
>> do.
>>
>> It is good practice to validate and condition data before inserting
>into
>> a database.
>>
>> Consider trimming the data before doing the INSERT.
>>
>I do validate my data by quoting it but I never expected to have to do
>a 
>trim to remove a LF.  Especially on an iphone for input, since it's not
>
>easy to enter a LF.

Quoting the data is not the same thing as validating it.

Thanks,
Ash

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread John Meyer

MOTS:  never take any input on faith.


Jim Giner wrote:

On 7/5/2013 3:02 PM, Stephen wrote:

On 13-07-05 02:50 PM, Jim Giner wrote:


Now the question is - how the heck did I put that in there? Certainly
not intentionally.  The data is captured from a d/e screen I wrote and
it simply grabs the post value and inserts a new record with that
value along with some other values.  And I don't see anything
concatenating a LF to my string.


Is this a browser being used for input? Never assume what a browser will
do.

It is good practice to validate and condition data before inserting into
a database.

Consider trimming the data before doing the INSERT.

I do validate my data by quoting it but I never expected to have to do 
a trim to remove a LF.  Especially on an iphone for input, since it's 
not easy to enter a LF.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Jim Giner

On 7/5/2013 3:02 PM, Stephen wrote:

On 13-07-05 02:50 PM, Jim Giner wrote:


Now the question is - how the heck did I put that in there? Certainly
not intentionally.  The data is captured from a d/e screen I wrote and
it simply grabs the post value and inserts a new record with that
value along with some other values.  And I don't see anything
concatenating a LF to my string.


Is this a browser being used for input? Never assume what a browser will
do.

It is good practice to validate and condition data before inserting into
a database.

Consider trimming the data before doing the INSERT.

I do validate my data by quoting it but I never expected to have to do a 
trim to remove a LF.  Especially on an iphone for input, since it's not 
easy to enter a LF.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Stephen

On 13-07-05 02:50 PM, Jim Giner wrote:


Now the question is - how the heck did I put that in there? Certainly 
not intentionally.  The data is captured from a d/e screen I wrote and 
it simply grabs the post value and inserts a new record with that 
value along with some other values.  And I don't see anything 
concatenating a LF to my string.



Is this a browser being used for input? Never assume what a browser will do.

It is good practice to validate and condition data before inserting into 
a database.


Consider trimming the data before doing the INSERT.

--
Stephen


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Jim Giner

On 7/5/2013 2:42 PM, Matijn Woudt wrote:

On Fri, Jul 5, 2013 at 8:39 PM, Jim Giner wrote:


  I checked them in the db manually.  Clicked on the name, selected it, no
extra space highlighted.  Cursored through the length of the value - no
extra movements.



That does still not guarantee there are no extra characters. Some
characters are just not visible (NUL, CR, LF, ..)




On 7/5/2013 2:36 PM, Matijn Woudt wrote:




On Fri, Jul 5, 2013 at 8:33 PM, Jim Giner wrote:


On 7/5/2013 1:32 PM, shiplu wrote:


On Fri, Jul 5, 2013 at 11:10 PM, Jim Giner 
wrote:


  Mike Hall  comes back as 10, not 9

F.B. comes back as 5, not 4.



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.


  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?





And the answer is - yes, there is a LF char at the end of my data in my 
whole table.


Now the question is - how the heck did I put that in there?  Certainly 
not intentionally.  The data is captured from a d/e screen I wrote and 
it simply grabs the post value and inserts a new record with that value 
along with some other values.  And I don't see anything concatenating a 
LF to my string.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread Matijn Woudt
On Fri, Jul 5, 2013 at 8:39 PM, Jim Giner wrote:

>  I checked them in the db manually.  Clicked on the name, selected it, no
> extra space highlighted.  Cursored through the length of the value - no
> extra movements.
>

That does still not guarantee there are no extra characters. Some
characters are just not visible (NUL, CR, LF, ..)


>
> On 7/5/2013 2:36 PM, Matijn Woudt wrote:
>
>
>
>
> On Fri, Jul 5, 2013 at 8:33 PM, Jim Giner wrote:
>
>> On 7/5/2013 1:32 PM, shiplu wrote:
>>
>>> On Fri, Jul 5, 2013 at 11:10 PM, Jim Giner >> >wrote:
>>>
>>>  Mike Hall  comes back as 10, not 9
 F.B. comes back as 5, not 4.


>>> 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.
>>>
>>>
>>>  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?
>
>
>


Re: [PHP] strlen ?

2013-07-05 Thread Matijn Woudt
On Fri, Jul 5, 2013 at 8:33 PM, Jim Giner wrote:

> On 7/5/2013 1:32 PM, shiplu wrote:
>
>> On Fri, Jul 5, 2013 at 11:10 PM, Jim Giner 
>> **wrote:
>>
>>  Mike Hall  comes back as 10, not 9
>>> F.B. comes back as 5, not 4.
>>>
>>>
>> 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.
>>
>>
>>  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?


Re: [PHP] strlen ?

2013-07-05 Thread Jim Giner

On 7/5/2013 1:32 PM, shiplu wrote:

On Fri, Jul 5, 2013 at 11:10 PM, Jim Giner wrote:


Mike Hall  comes back as 10, not 9
F.B. comes back as 5, not 4.



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.


Why would I need to trim something that I can already see doesn't have 
any trailing or leading characters?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen ?

2013-07-05 Thread shiplu
On Fri, Jul 5, 2013 at 11:10 PM, Jim Giner wrote:

> Mike Hall  comes back as 10, not 9
> F.B. comes back as 5, not 4.
>

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.


-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] strlen ?

2013-07-05 Thread John Meyer

Jim Giner wrote:
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.


Ex.

Mike Hall  comes back as 10, not 9
F.B. comes back as 5, not 4.

I've looked at my data and counted the chars - there is no extra space 
at the beginning or end in my table.


Anyone have an explanation?


Does strlen count the line feed?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen question

2004-07-23 Thread Jake Stonebender
On Fri, 23 Jul 2004 09:34:24 -0500, Jake Stonebender
<[EMAIL PROTECTED]> wrote:


That's what I actually meant.  Sorry.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen question

2004-07-23 Thread Jake Stonebender


I'm shooting for succinctness here.  I'd like to see if someone has a
shorter solution.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strlen question

2004-07-23 Thread Matt M.
> the form is separated into 5 sections and if there are no items filled out
> in that section, then i need to hide the title too.
> 
> I have been playing around with the syntax and am not having any
> success...any suggestions?
> 
> here is a sample of what i am trying:
> 
>   0) { ?>
> 
> 


 0 || strlen($_POST['item02']) > 0
||  strlen($_POST['item03']) > 0) { ?>
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] strlen() gives a wrong count

2002-03-19 Thread Rasmus Lerdorf

Think you could post a base64_encode() version of that string?

On Tue, 19 Mar 2002, Gil Disatnik wrote:

> Of course.
> Following is a part Hebrew part English text I have in my phorum, it
> probably won't look good on a system without Hebrew support.
>
> String on a file:
> --->snip<---
> îé ùøåöä îåæîð/ú ìëúåá àú ùìå...(àí éù).
>
> 370304 - DooG
>
> îäçìåöéí P-:
>
>
> NP - King Crimson - Beat
> --->snip<---
>
> wc -c testfile says it's 98
> sed 's/\ //g' testfile | wc -c says it's 83
>
>
>
> The same string on a php variable:
> --->snip<---
> $chars="îé ùøåöä îåæîð/ú ìëúåá àú ùìå...(àí éù).
>
> 370304 - DooG
>
> îäçìåöéí P-:
>
>
> NP - King Crimson - Beat";
> --->snip<---
> strlen($chars); says 104
> strlen(str_replace(" ","",$chars)); says 89...
>
>
> Thank you for the help!
>
>
> At 13:19 19/03/2002 -0700, Darren Gamble wrote:
> >Good day,
> >
> >Could you post this mystery string so that we could help you?
> >
> >
> >Darren Gamble
> >Planner, Regional Services
> >Shaw Cablesystems GP
> >630 - 3rd Avenue SW
> >Calgary, Alberta, Canada
> >T2P 4L4
> >(403) 781-4948
> >
> >
> >-Original Message-
> >From: Gil Disatnik [mailto:[EMAIL PROTECTED]]
> >Sent: Tuesday, March 19, 2002 1:12 PM
> >To: [EMAIL PROTECTED]
> >Subject: [PHP] strlen() gives a wrong count
> >
> >
> >Hello there,
> >
> >I have a 98 characters string (including spaces), wc -c says it's 98
> >characters and a file containing this string is 98 bytes as well.
> >
> >For some reason - strlen() says it's more... it says it's a 104 characters
> >strings, when I removed the spaces (using sed on the shell and using
> >str_replace on php) - wc said it's 83 characters and strlen() said it's
> >89...
> >
> >How could that be? is there another way to get the exact number of
> >characters in a string?
> >
> >Thanks.
> >
> >
> >
> >Regards
> >
> >Gil Disatnik
> >UNIX system/security administrator.
> >
> >GibsonLP@EFnet
> >
> >_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> >"Windows NT has detected mouse movement, you MUST restart
> >your computer before the new settings will take effect, [ OK ]"
> >
> >Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
> >system, written for a 4 bit processor by a 2 bit company which can
> >not stand 1 bit of competition.
> >-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
> >
> >
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> Regards
>
> Gil Disatnik
> UNIX system/security administrator.
>
> GibsonLP@EFnet
>
> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> "Windows NT has detected mouse movement, you MUST restart
> your computer before the new settings will take effect, [ OK ]"
> 
> Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
> system, written for a 4 bit processor by a 2 bit company which can
> not stand 1 bit of competition.
> -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] strlen() gives a wrong count

2002-03-19 Thread Gil Disatnik

Of course.
Following is a part Hebrew part English text I have in my phorum, it 
probably won't look good on a system without Hebrew support.

String on a file:
--->snip<---
îé ùøåöä îåæîð/ú ìëúåá àú ùìå...(àí éù).

370304 - DooG

îäçìåöéí P-:


NP - King Crimson - Beat
--->snip<---

wc -c testfile says it's 98
sed 's/\ //g' testfile | wc -c says it's 83



The same string on a php variable:
--->snip<---
$chars="îé ùøåöä îåæîð/ú ìëúåá àú ùìå...(àí éù).

370304 - DooG

îäçìåöéí P-:


NP - King Crimson - Beat";
--->snip<---
strlen($chars); says 104
strlen(str_replace(" ","",$chars)); says 89...


Thank you for the help!


At 13:19 19/03/2002 -0700, Darren Gamble wrote:
>Good day,
>
>Could you post this mystery string so that we could help you?
>
>
>Darren Gamble
>Planner, Regional Services
>Shaw Cablesystems GP
>630 - 3rd Avenue SW
>Calgary, Alberta, Canada
>T2P 4L4
>(403) 781-4948
>
>
>-Original Message-
>From: Gil Disatnik [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, March 19, 2002 1:12 PM
>To: [EMAIL PROTECTED]
>Subject: [PHP] strlen() gives a wrong count
>
>
>Hello there,
>
>I have a 98 characters string (including spaces), wc -c says it's 98
>characters and a file containing this string is 98 bytes as well.
>
>For some reason - strlen() says it's more... it says it's a 104 characters
>strings, when I removed the spaces (using sed on the shell and using
>str_replace on php) - wc said it's 83 characters and strlen() said it's
>89...
>
>How could that be? is there another way to get the exact number of
>characters in a string?
>
>Thanks.
>
>
>
>Regards
>
>Gil Disatnik
>UNIX system/security administrator.
>
>GibsonLP@EFnet
>
>_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>"Windows NT has detected mouse movement, you MUST restart
>your computer before the new settings will take effect, [ OK ]"
>
>Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
>system, written for a 4 bit processor by a 2 bit company which can
>not stand 1 bit of competition.
>-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


Regards

Gil Disatnik
UNIX system/security administrator.

GibsonLP@EFnet

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
"Windows NT has detected mouse movement, you MUST restart
your computer before the new settings will take effect, [ OK ]"

Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
system, written for a 4 bit processor by a 2 bit company which can
not stand 1 bit of competition.
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


RE: [PHP] strlen() gives a wrong count

2002-03-19 Thread Darren Gamble

Good day,

Could you post this mystery string so that we could help you?


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Gil Disatnik [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 19, 2002 1:12 PM
To: [EMAIL PROTECTED]
Subject: [PHP] strlen() gives a wrong count


Hello there,

I have a 98 characters string (including spaces), wc -c says it's 98 
characters and a file containing this string is 98 bytes as well.

For some reason - strlen() says it's more... it says it's a 104 characters 
strings, when I removed the spaces (using sed on the shell and using 
str_replace on php) - wc said it's 83 characters and strlen() said it's
89...

How could that be? is there another way to get the exact number of 
characters in a string?

Thanks.



Regards

Gil Disatnik
UNIX system/security administrator.

GibsonLP@EFnet

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
"Windows NT has detected mouse movement, you MUST restart
your computer before the new settings will take effect, [ OK ]"

Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
system, written for a 4 bit processor by a 2 bit company which can
not stand 1 bit of competition.
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] strlen() gives a wrong count

2002-03-19 Thread Rasmus Lerdorf

Well, how are you putting it into the string?

On Tue, 19 Mar 2002, Gil Disatnik wrote:

> Hello there,
>
> I have a 98 characters string (including spaces), wc -c says it's 98
> characters and a file containing this string is 98 bytes as well.
>
> For some reason - strlen() says it's more... it says it's a 104 characters
> strings, when I removed the spaces (using sed on the shell and using
> str_replace on php) - wc said it's 83 characters and strlen() said it's 89...
>
> How could that be? is there another way to get the exact number of
> characters in a string?
>
> Thanks.
>
>
>
> Regards
>
> Gil Disatnik
> UNIX system/security administrator.
>
> GibsonLP@EFnet
>
> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> "Windows NT has detected mouse movement, you MUST restart
> your computer before the new settings will take effect, [ OK ]"
> 
> Windows is a 32 bit patch to a 16 bit GUI based on a 8 bit operating
> system, written for a 4 bit processor by a 2 bit company which can
> not stand 1 bit of competition.
> -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] strlen

2001-07-25 Thread David Robley

On Thu, 26 Jul 2001 05:49, David OBrien wrote:
> I'm having a heck of a time getting something to work like it should
>
> I have a script which reads a list of words one per line
> I want it to display the length of the word a tab then the word. No
> matter how I code it it still only shows the word alone on strlen. Any
> ideas?
>
>  $handle = fopen ("./ospd3.txt", "r");
> while (!feof($handle)) {
> $wordlist[]=fread($handle,4096);
> }
> fclose($handle);
> uasort($wordlist, "sortbylength");
> foreach ($wordlist as $word) {
> $lent = strlen($word);
> print "$lent"."\t"."$word"."\n";
> }
> exit;
>
>
> function sortbylength($arr,$brr) {
> $alen = strlen($arr);
> $blen = strlen($brr);
> if ($alen == $blen) {
> return 0;
> }
> return ($alen > $blen) ?  -1 : 1;
> }
> ?>
>
> sample of the ospd3.txt


> Thanks

If you are outputting that to a browser, be aware that, unless the output 
is enclosed in  tags, the browser will ignore the tabs. Tabs, 
multiple spaces and end of line dharacters are all ignored.

Alternatively, you could build it into a  structure.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Not a real tagline, but an incredible soy substitute.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]