Re: printf / sprintf function usage




"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"
?>


.



Relevant Pages

  • Re: hacking games
    ... I can't seem to find the original post to quote, ... Defense Intelligence Agency ... Circumvent PHP filters for XSS ... Backdoor is listening on host - find it ...
    (Security-Basics)
  • Re: WebMin and Apache 1.x and 2.x both installed?
    ... my functioning drupal and phpmyadmin installs - it looks like the mime type ... the PHP issue. ... Sometimes you can look at a problem and consider what error messages you received, what symptoms you observed, whether or not any errors or useful messages were displayed in the log files... ... (Your original post just wasn't informative enough for me to comment on the Apache issues you described, ...
    (Ubuntu)
  • Re: BT suck
    ... |> the habbit of getting it wrong mon petite ami. ... | reccomended and wrote the PHP for me months after buying the webspace. ... | again my original post. ...
    (uk.net.web.authoring)
  • Re: [PHP] how do i get a printout of original multipart post data
    ... what is the thought behind php not providing access to original post ...
    (php.general)
  • Re: printf / sprintf function usage
    ... 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. ... it didn't say that in so many words - but the rules sprintf() and printffollow are in there. ...
    (comp.lang.php)