"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:G9******************************@comcast.com. ..
Dave wrote:
>"Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:fk**********@hercules.cohp1...
>>Dave wrote:
Can I do a similar operation with printf/sprintf in PHP?
Yes.
RTFM on sprintf and printf: http://php.net/printf ;
http://php.net/sprintf
I did, read the manual before posting. There is nothing mentioning the
usage I have described in my original post. Note question was, whether I
could use %%s in the first instance of sprintf and than use the resulting
%s literal as a placeholder to the second printf.
Dave,
No, it didn't say that in so many words - but the rules sprintf() and
printf() follow are in there.
And yes, it works just fine. Did you try it?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jerry,
Yes, I tried the concept. For some reason it did not work in the real code I
was using, but the awk example I provided in my original post worked when I
rewrote for PHP. So I now know it's working. Thanks:
<?php
/*
# awk example
var1="x";
temp = sprintf("Variable 1: %s Variable 2: %%s", var1);
var2="y";
printf(temp,var2);
# In awk the above will output: "Variable 1: x Variable 2: y"
*/
$var1="x";
$temp = sprintf("Variable 1: %s Variable 2: %%s", $var1);
$var2="y";
printf($temp,$var2);
// In PHP the above will output: "Variable 1: x Variable 2: y"
?>