Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24900 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73000 invoked by uid 1010); 23 Jul 2006 10:19:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 72985 invoked from network); 23 Jul 2006 10:19:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2006 10:19:01 -0000 X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 209.142.136.132 msa2-mx.centurytel.net Linux 2.4/2.6 Received: from ([209.142.136.132:59487] helo=msa2-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id 80/97-04178-4B343C44 for ; Sun, 23 Jul 2006 05:39:01 -0400 Received: from pc1 (ppp1096.lr.centurytel.net [64.91.12.199]) by msa2-mx.centurytel.net (8.13.6/8.13.6) with SMTP id k6N9cvx6019900; Sun, 23 Jul 2006 04:38:57 -0500 Message-ID: <00a301c6ae3b$d23e2770$0201a8c0@pc1> To: , "Gwynne" References: <018101c6abf6$ee273810$0201a8c0@pc1> <105846538.20060720212112@marcus-boerger.de> <532686B2-88F2-4FCE-BAE1-31AE208FFE12@skytag.com> Date: Sun, 23 Jul 2006 04:38:57 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Subject: Re: [PHP-DEV] [v][sf]printf additions (#, E, g, G) From: php_lists@realplain.com ("Matt W") Hi Gwynne, ----- Original Message ----- From: "Gwynne" Sent: Saturday, July 22, 2006 > On Jul 20, 2006, at 3:21 PM, Marcus Boerger wrote: > >> I've wished there was a *printf() float specifier that wouldn't > >> include > >> trailing zeros/point, as simply converting to string (echo, %s, > >> etc.) can > >> result in scientific notation, which I *don't* want (%g in > >> convert_to_string()). The only other way that would result in > >> what I want > >> is number_format() with my "no-extra-zeros option" patch. ;-) So > >> I was > >> originally looking for how to NOT pad %f to the specified > >> precision, then I > >> thought why not add more of the stuff from C? (And I see it's > >> marked "not > >> done" in formatted_print.c.) > > > >> Can/should I go ahead and add support for the # flag/specifier, g/ > >> G, and E > >> (the missing compliment to e)? Make everything work like C, > >> except # used > >> with f/F, which would mean "remove trailing 0's/point" -- as C's > >> behavior > >> with # and f (add point even when precision=0?) can be done in > >> PHP. (I > >> assume C's is for when precision is specified with * + parameter?) > > Having more conversion specifiers here won't hurt. If it can be done > > in a way compatible to other languages especially like C it should be > > done in that way. If PHP has already closed the way by choosing > > opposite > > defaults the opposite should everntually also work. > > While we're on the subject, one of my favorite personal patches to > PHP is one that adds the %n specifier. The parameter to %n is a > reference which recieves the total length of the string with all > replacements so far. %n itself is replaced by nothing at all. You > could do this with $n = strlen( $s = sprintf( blah blah blah ) ) + > strlen( $s .= sprintf( the rest of the blah ) );, but it's a very > nice shortcut if you need the replaced length in the middle of the > conversion or for a situation like this (and the above doesn't work > too well if you have positional params!): > > printf( "Some processing message with %s replacements...%n", 'some', & > $n ); > // do some stuff here > print str_repeat( ' ', $n ) . "\rSome status text here that doesn't > worry about whether the replaced text was longer."; > > Here's the printf(3) manpage description for %n (MacOS X system, BSD > manpage): > > n The number of characters written so far is stored into > the inte- > ger indicated by the int * (or variant) pointer > argument. No > argument is converted. > > Any chance of getting this into PHP? I can provide a patch. > > -- Gwynne, Daughter of the Code > "This whole world is an asylum for the incurable." I had thought about adding %n too, but didn't know what the reaction would be or if it'd be used. (And the length thing would have to be changed [later] for Unicode length or such, I assume?) Also, wasn't sure about the internals code for the reference and writing to it, etc. :-) Sounds fine to me though, if your patch can be applied. If PHP gets these additions, it'll have all of C's except %p I guess. :-) Matt