Path: csiph.com!usenet.pasdenom.info!poup.poupinou.org!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <5795699.ZddputCnCo@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 30 Mar 2013 20:18:06 +0100 User-Agent: KNode/4.8.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <98cc9763-7f32-4ca7-9d52-f698c222f246@n2g2000yqg.googlegroups.com> <2206171.g8a4ScMWm9@PointedEars.de> <1l036uh.tti447p1ww4uN%adrian@poppyrecords.invalid.invalid> <1396959.N3YltuB2Mg@PointedEars.de> <2177849.7jHvAoTLnH@PointedEars.de> <2391743.1T8NqQ3TJ8@PointedEars.de> MIME-Version: 1.0 Lines: 38 NNTP-Posting-Date: 30 Mar 2013 20:18:07 CET NNTP-Posting-Host: 6bd629fd.newsspool1.arcor-online.net X-Trace: DXC=mBN1TjCGo[j>jlK2>IgHGdic==]BZ:afn4Fo<]lROoRankgeX?EC@@`KPeR?^YhTLgDZm8W4\YJNlb@mF9jNikdeBoKGPB=12AgTaH3kXcWb[k X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.php:8921 Christoph Becker wrote: > I am more concerned about the number of characters the string holds. > Say, I want to get the last character: > > $str = '€'; > echo $str[2]; > >> Because lack of precision in font reproduction, or even in guaranteeing >> which font may be selected, renders the former an 'open' question. >> >> strlen('€')===3 is in fact the correct answer. That depends on the character encoding of the source code. 3 is the correct answer for an *UTF-8*-encoded U+20AC EURO SIGN character, which is then encoded E2 82 AC. [1] > I suppose most *higher level languages* define the length of a string as > the number of characters the string holds. Cf. ECMAScript's length > property and TCL's [string length]. Even PHP's mb_strlen() returns the > number of characters. AISB, unfortunately the “length” property of ECMAScript String instances is not a good example in that regard as it does _not_ mean the number of characters but the number of 16-bit units (UTF-16 code units, usually). That is only less obvious than with UTF-8 because all Unicode characters in the BMP can be encoded using only one such unit. (I am working on a workaround; you could call it “an mb_strlen() for ECMAScript implementations”.) PointedEars ___________ [1] -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, (2004)