Re: [PHP-DEV] foreach() for strings

2011-06-23 Thread Larry Garfield
On 06/20/2011 10:25 AM, John Crenshaw wrote: Doing this with an explicit iterator object is a fine idea. The syntax becomes something like: foreach(new TextIterator($s, 'UTF8') as $pos=$c) { ... } On the other hand, I think that trying to support iteration without using an iterator

Re: [PHP-DEV] foreach() for strings

2011-06-23 Thread Jan Schneider
Zitat von Larry Garfield la...@garfieldtech.com: On 06/20/2011 10:25 AM, John Crenshaw wrote: Doing this with an explicit iterator object is a fine idea. The syntax becomes something like: foreach(new TextIterator($s, 'UTF8') as $pos=$c) { ... } On the other hand, I think that trying

RE: [PHP-DEV] foreach() for strings

2011-06-23 Thread John Crenshaw
-Original Message- From: Jan Schneider [mailto:j...@horde.org] And if that very same string that's supposed to be an array is processed using the $var[$n] syntax nowadays is any different? It's not, you won't get an error message for that either, and it's the same amount of

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 07:24, schrieb Tomas Kuliavas: 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() Such function uses six lines in PHP. so why do you not post them? You can write your own. no i can not as said I need locale insensitive

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Gustavo Lopes
Em Wed, 22 Jun 2011 12:14:40 +0100, Reindl Harald h.rei...@thelounge.net escreveu: Am 22.06.2011 07:24, schrieb Tomas Kuliavas: 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() Such function uses six lines in PHP. so why do you not post

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 14:14, schrieb Gustavo Lopes: Em Wed, 22 Jun 2011 12:14:40 +0100, Reindl Harald h.rei...@thelounge.net escreveu: Am 22.06.2011 07:24, schrieb Tomas Kuliavas: 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() Such function uses

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Kalle Sommer Nielsen
2011/6/22 Reindl Harald h.rei...@thelounge.net: WTF should this do? this won't return boolean It's an expression, so its evaluated result is a boolean hence why it makes sense -- regards, Kalle Sommer Nielsen ka...@php.net -- PHP Internals - PHP Runtime Development Mailing List To

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Gustavo Lopes
Em Wed, 22 Jun 2011 13:21:10 +0100, Reindl Harald h.rei...@thelounge.net escreveu: Am 22.06.2011 14:14, schrieb Gustavo Lopes: It's actually 3 lines: function str_is_utf8($str) { return $str == || htmlspecialchars($str, 0, UTF-8); } WTF should this do? this won't return boolean

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:30, schrieb Gustavo Lopes: Em Wed, 22 Jun 2011 13:21:10 +0100, Reindl Harald h.rei...@thelounge.net escreveu: Am 22.06.2011 14:14, schrieb Gustavo Lopes: It's actually 3 lines: function str_is_utf8($str) { return $str == || htmlspecialchars($str, 0, UTF-8); }

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Lars Schultz
Am 22.06.2011 15:40, schrieb Reindl Harald: and why this will not return true if $str is ISO-8859-1? If you RTFM (in your jargon) you would know. http://ch.php.net/manual/en/function.htmlspecialchars.php (Return value Section) -- PHP Internals - PHP Runtime Development Mailing List To

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Anthony Ferrara
and why this will not return true if $str is ISO-8859-1? For lower 7 bit characters (code points = 127) it would return true. But if there is a single higher character (outside of ascii), it would only return true if the byte sequences follow UTF-8 semantics. So it would return false if

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:45, schrieb Lars Schultz: Am 22.06.2011 15:40, schrieb Reindl Harald: and why this will not return true if $str is ISO-8859-1? If you RTFM (in your jargon) you would know. http://ch.php.net/manual/en/function.htmlspecialchars.php (Return value Section) i read the

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Olivier Hill
Please change your tone. Thank you. Olivier -- http://www.olivierhill.ca/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Rasmus Lerdorf
On 06/22/2011 06:52 AM, Reindl Harald wrote: Am 22.06.2011 15:45, schrieb Lars Schultz: Am 22.06.2011 15:40, schrieb Reindl Harald: and why this will not return true if $str is ISO-8859-1? If you RTFM (in your jargon) you would know.

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:55, schrieb Olivier Hill: Please change your tone. Thank you the tonhe is quite correct for peopole who think a quick 3 liner will do the job of UTF8 detection which it does not and there you can read the manual as often you want signature.asc Description: OpenPGP

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: There is obviously no way to tell if hello is UTF-8 or ISO-8859-1. It is technically impossible since the two are identical in that range. yes and so this will not work and as long PHP has on million places troubles with UTF8 it would be hardly

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Rasmus Lerdorf
On 06/22/2011 07:01 AM, Reindl Harald wrote: Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: There is obviously no way to tell if hello is UTF-8 or ISO-8859-1. It is technically impossible since the two are identical in that range. yes and so this will not work and as long PHP has on

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 16:06, schrieb Rasmus Lerdorf: On 06/22/2011 07:01 AM, Reindl Harald wrote: Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: There is obviously no way to tell if hello is UTF-8 or ISO-8859-1. It is technically impossible since the two are identical in that range. yes and so

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Ferenc Kovacs
On Wed, Jun 22, 2011 at 4:08 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 22.06.2011 16:06, schrieb Rasmus Lerdorf: On 06/22/2011 07:01 AM, Reindl Harald wrote: Am 22.06.2011 15:57, schrieb Rasmus Lerdorf: There is obviously no way to tell if hello is UTF-8 or ISO-8859-1. It

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
Am 22.06.2011 16:49, schrieb Ferenc Kovacs: after 10 years i want solutions where it is not the road to hell using any string function on user-input and since PHP6 seems to be quite dead it feels there will never be a trustable solution you made my day. boy :) after fetch a

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Ferenc Kovacs
On Wed, Jun 22, 2011 at 4:52 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 22.06.2011 16:49, schrieb Ferenc Kovacs: after 10 years i want solutions where it is not the road to hell using any string function on user-input and since PHP6 seems to be quite dead it feels

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Robert Eisele
1. The number of CHARs isn't unrelevant in a general manner. It depents on the application, even if the trend goes towards UTF8 for websites. 2. Within 10 years, you could have come to a working solution which could please us all. 3. Stop flaming and focus on your other day-job instead.

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Reindl Harald
FIRST: it is terrible that one post in HTML, the next ansers on top and other answering on bottom in the same thread and that the most do not undertsand reply to the list address is enough Am 22.06.2011 17:07, schrieb Robert Eisele: 1. The number of CHARs isn't unrelevant in a general manner

RE: [PHP-DEV] foreach() for strings

2011-06-22 Thread Jonathan Bond-Caron
On Wed Jun 22 11:25 AM, Reindl Harald wrote: and php as primary web-language is missing UTF8 support in the core You have a valid point. Now onto foreach() for strings, any other opinions? Seems like the discussion is closed and most likely should move to a RFC with some consideration about

Re: [PHP-DEV] foreach() for strings

2011-06-22 Thread Tomas Kuliavas
2011.06.22 14:14 Reindl Harald rašė: Am 22.06.2011 07:24, schrieb Tomas Kuliavas: 2011.06.21 23:27 Reindl Harald rašė: i do not understand any word and miss a simple str_is_utf8() Such function uses six lines in PHP. so why do you not post them? My lines are not public domain. They are

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Derick Rethans
On Mon, 20 Jun 2011, Stas Malyshev wrote: On 6/20/11 9:15 AM, John Crenshaw wrote: From: Ilia Alshanetsky [mailto:i...@prohost.org] As long as it works on a premise that a string is a byte array and each element represents 1 byte, +1 from me. Code written on this premise is

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 12:53 PM, Derick Rethans der...@php.net wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal here, as it is about byte,

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Lester Caine
Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal here, as it is about byte, not characters :) I believe this may be where some

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 1:33 PM, Lester Caine les...@lsces.co.uk wrote: Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in  PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated to the proposal

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Lester Caine
Pierre Joye wrote: On Tue, Jun 21, 2011 at 1:33 PM, Lester Caineles...@lsces.co.uk wrote: Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
Pierre Joye wrote: On Tue, Jun 21, 2011 at 1:33 PM, Lester Caineles...@lsces.co.uk wrote: Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl, actually. But that's somehow unrelated

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Pierre Joye
On Tue, Jun 21, 2011 at 4:38 PM, John Crenshaw johncrens...@priacta.com wrote: This mindset is fundamentally broken. You can call it a byte array all you want, but the truth is that 99.999% of the time, when a developer is using a string they need it for characters, not for bytes Let me

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 17:38 John Crenshaw rašė: Pierre Joye wrote: On Tue, Jun 21, 2011 at 1:33 PM, Lester Caineles...@lsces.co.uk wrote: Pierre Joye wrote: It depended on ICU there, and I would be against making a core thing in PHP 5.x depend on ICU. It can and should be done as part of intl,

Re: RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread Arvids Godjuks
As a userland developer due to my geographical nature i have to work with 3 languages constantly - english, russian (cyryllic) and latvian (witch has it's own share of non latin characters). I end up using utf-8 in every project. And some give me a headake of dealing with text parsing. mb_string

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 17:55, schrieb Tomas Kuliavas: They submit it in utf-8 only if your html form allows them to do that or they don't follow html specification and try to exploit your form. Set form input charset to iso-8859-1 and your nbspace will take only one byte. and this naive attitude is

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Ferenc Kovacs
On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 21.06.2011 17:55, schrieb Tomas Kuliavas: They submit it in utf-8 only if your html form allows them to do that or they don't follow html specification and try to exploit your form. Set form input charset to

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 18:22, schrieb Ferenc Kovacs: On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 21.06.2011 17:55, schrieb Tomas Kuliavas: They submit it in utf-8 only if your html form allows them to do that or they don't follow html specification and try to

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Ferenc Kovacs
On Tue, Jun 21, 2011 at 6:24 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 21.06.2011 18:22, schrieb Ferenc Kovacs: On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald h.rei...@thelounge.net wrote: Am 21.06.2011 17:55, schrieb Tomas Kuliavas: They submit it in utf-8 only if your

RE: RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
They submit it in utf-8 only if your html form allows them to do that or they don't follow html specification and try to exploit your form. If no explicit encoding is given, all modern browsers will attempt to autodetect the encoding based on the page contents, often with unpredictable

RE: [PHP-DEV] foreach() for strings

2011-06-21 Thread John Crenshaw
From: Pierre Joye [mailto:pierre@gmail.com] On Tue, Jun 21, 2011 at 4:38 PM, John Crenshaw johncrens...@priacta.com wrote: This mindset is fundamentally broken. You can call it a byte array all you want, but the truth is that 99.999% of the time, when a developer is using a

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 19:24 Reindl Harald rašė: Am 21.06.2011 18:22, schrieb Ferenc Kovacs: On Tue, Jun 21, 2011 at 6:14 PM, Reindl Harald h.rei...@thelounge.netwrote: Am 21.06.2011 17:55, schrieb Tomas Kuliavas: They submit it in utf-8 only if your html form allows them to do that or they don't

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 19:12, schrieb Tomas Kuliavas: and this naive attitude is the root of most security problems! why do you believe that every client submission is coming over your form or generally over anything you can control? that doesn't matter here, Tomas just corrected John, that his

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Tomas Kuliavas
2011.06.21 20:51 Reindl Harald rašė: utf-8 is strict format. If you expect utf-8 and someone submits something else, you can tell that without any string function. You can verify utf-8 strings in pcre. You can convert nbspace to regular space, if you want. utf-8 does not have any byte

Re: [PHP-DEV] foreach() for strings

2011-06-21 Thread Reindl Harald
Am 21.06.2011 22:19, schrieb Tomas Kuliavas: 2011.06.21 20:51 Reindl Harald rašė: utf-8 is strict format. If you expect utf-8 and someone submits something else, you can tell that without any string function. You can verify utf-8 strings in pcre. You can convert nbspace to regular space,

[PHP-DEV] foreach() for strings

2011-06-20 Thread Robert Eisele
foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. If you want to implement a parser in PHP, you have to go the way with for + strlen + substr() or $x[$i] to address one character

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. If you want to implement a parser in PHP, you have to go the way with for +

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Robert Eisele
2011/6/20 Derick Rethans der...@php.net On Mon, 20 Jun 2011, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. If you want to implement a parser

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Johannes Schlüter
On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. I would prefer a TextIterator as we had in the old PHP 6 as this

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Johannes Schlüter wrote: On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. I would prefer a

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Derick Rethans
On Mon, 20 Jun 2011, Robert Eisele wrote: 2011/6/20 Derick Rethans der...@php.net On Mon, 20 Jun 2011, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Pierre Joye
2011/6/20 Johannes Schlüter johan...@schlueters.de: On Mon, 2011-06-20 at 13:27 +0200, Robert Eisele wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. I would prefer

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Pierre Joye
hi Robert, I would go with a RFC for that one, at least to document/cover edge cases to help the doc team to properly document this change if it gets approved. Thanks for your work so far! On Mon, Jun 20, 2011 at 1:27 PM, Robert Eisele rob...@xarg.org wrote: foreach() has many functions,

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread Jonathan Bond-Caron
On Mon Jun 20 09:11 AM, Lee davis wrote: Could we also use current(), next() and key() for iteration of strings? $string = 'string'; while ($char = current($string)) { echo key($string) // Would output the offset position I assume 0,1,2 etc?? echo $char // outputs each letter

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Ilia Alshanetsky
As long as it works on a premise that a string is a byte array and each element represents 1 byte, +1 from me. On Mon, Jun 20, 2011 at 7:27 AM, Robert Eisele rob...@xarg.org wrote: foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread John Crenshaw
-Original Message- From: Lee davis [mailto:leedavi...@gmail.com] Sent: Monday, June 20, 2011 9:12 AM To: Robert Eisele Cc: internals@lists.php.net Subject: Re: [PHP-DEV] foreach() for strings I think this would be quite a useful feature, and am In favor of it. However, I think

Re: [PHP-DEV] foreach() for strings

2011-06-20 Thread Stas Malyshev
Hi! foreach() has many functions, looping over arrays, objects and implementing the iterator interface. I think it's also quite intuitive to use foreach() for strings, too. I'm not sure how you'd implement such thing, but then I think things like next(), end(), etc. should work too... --

RE: [PHP-DEV] foreach() for strings

2011-06-20 Thread John Crenshaw
From: Ilia Alshanetsky [mailto:i...@prohost.org] As long as it works on a premise that a string is a byte array and each element represents 1 byte, +1 from me. Code written on this premise is almost always bug central when people finally get around to realizing why they really do need to