Re: printf / sprintf function usage
- From: "Dave" <withheld@xxxxxxxxxxxxx>
- Date: Tue, 18 Dec 2007 08:50:01 -0500
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> wrote in message
news:G9mdnbQF_dJYbvvanZ2dnUVZ_v7inZ2d@xxxxxxxxxxxxxx
Dave wrote:
"Iván Sánchez Ortega" <ivansanchez-alg@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message news:fk6k09$blu$1@xxxxxxxxxxxxxxxxx
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.
jstucklex@xxxxxxxxxxxxx
==================
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"
?>
.
- References:
- printf / sprintf function usage
- From: Dave
- Re: printf / sprintf function usage
- From: Dave
- Re: printf / sprintf function usage
- From: Jerry Stuckle
- printf / sprintf function usage
- Prev by Date: Re: PHP PAM
- Next by Date: Re: secure file uploads and downloads
- Previous by thread: Re: printf / sprintf function usage
- Next by thread: Re: printf / sprintf function usage
- Index(es):
Relevant Pages
|
|