note 9663 deleted from function.sprintf by cmb

From: Date: Sun, 02 Dec 2018 13:02:30 +0000
Subject: note 9663 deleted from function.sprintf by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209836@lists.php.net to get a copy of this message
Note Submitter: voudras at nospam dot swiftslayer dot org ---- Little note about sprintf and its ilk. if you attempt something like $string = "dingy%sflem%dwombat"; $nbr = 5; $name = "voudras"; $msg = sprintf("%d $string %s", $nbr, $name); sprintf will complain about a lack in the number of arguments, this would be because of the %'s in the actual string. This can be a great benifit, but is also rather confusing if you dont realize this feature, and are passing questionable variables to sprintf (for, say perhaps logging). One way around this is using ereg_replace("%","%%", $string); before sending it off to sprintf. This is actually how i came across this as a problem - i had realized some time ago that i would have to test my $string for %'s, but when running the %->%% replacement on a very large serialized object, my application timed out. My solution was to use sprintf("%d %s %s", $nbr, $string, $name); but, there was a reason i originally had done this the other way - i suppose i'll find out soon enough

« previous php.notes (#209836) next »