Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24883 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41418 invoked by uid 1010); 22 Jul 2006 18:44:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 41402 invoked from network); 22 Jul 2006 18:44:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jul 2006 18:44:48 -0000 X-PHP-List-Original-Sender: gwynne@skytag.com X-Host-Fingerprint: 208.97.132.62 sd-green-bigip-62.dreamhost.com Linux 2.4/2.6 Received: from ([208.97.132.62:43714] helo=spunkymail-a7.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id A7/E5-04178-E1272C44 for ; Sat, 22 Jul 2006 14:44:47 -0400 Received: from [192.168.0.101] (c-66-31-91-125.hsd1.ma.comcast.net [66.31.91.125]) by spunkymail-a7.dreamhost.com (Postfix) with ESMTP id BBE325BBE3 for ; Sat, 22 Jul 2006 11:44:43 -0700 (PDT) In-Reply-To: <105846538.20060720212112@marcus-boerger.de> References: <018101c6abf6$ee273810$0201a8c0@pc1> <105846538.20060720212112@marcus-boerger.de> Mime-Version: 1.0 (Apple Message framework v752.2) X-Priority: 3 (Normal) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: <532686B2-88F2-4FCE-BAE1-31AE208FFE12@skytag.com> Content-Transfer-Encoding: 7bit Date: Sat, 22 Jul 2006 14:44:34 -0400 To: internals@lists.php.net X-Mailer: Apple Mail (2.752.2) Subject: Re: [PHP-DEV] [v][sf]printf additions (#, E, g, G) From: gwynne@skytag.com (Gwynne) 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."