php3-list | 200003
Date: 03/31/00
- Next message: Leon Mergen: "Re: [PHP3] Re: [[PHP3] SMS]"
- Previous message: Gunnar Kristjansson: "[PHP3] How Can I cut "<" and ">""
- In reply to: Andreas Jung: "[PHP3] Variable substitution in sprintf() format string ?!"
- Next in thread: Andreas Jung: "Re: [PHP3] Variable substitution in sprintf() format string ?!"
- Reply: Andreas Jung: "Re: [PHP3] Variable substitution in sprintf() format string ?!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
When you use single quotes ( ' ) it means to take the string literally,
therefore
$s = '$row["x"]/%s';
literally means that string, no variable parsed. Use double quotes ( " ) to
pass a variable. BUT, as you can see that won't work because of the
associative array, this is what you do instead:
$s = $row["x"]."string";
However, on top of all that I don't see why you put the sprintf formatting
in the variable, this is unreadable to other programmers and senseless, why
not just do this in the first place:
$row = Array("x" => "teststring: ");
$dummy = "also a test";
echo sprintf("%s blabla\n%s blabla",$row["x"], $dummy);
Much more compact and neater.
Nick
----- Original Message -----
From: "Andreas Jung" <ajung <email protected>>
To: <php3 <email protected>>
Sent: Friday, March 31, 2000 1:43 PM
Subject: [PHP3] Variable substitution in sprintf() format string ?!
> Take a look the following code. I am trying to use a variable
> as format string for sprintf(). The string itsself contains
> some other variable that should be replaced within the sprintf()
> call however I are not replaced. I tried a lot with escaping $
> and quoting but without result. Maybe someone can help.
>
> <?
> $row = Array();
> $row["x"] = "teststring: ";
> $dummy = "also a test";
>
> $s = '$row["x"]/%s';
> $s1 = '$dummy/%s';
>
>
> echo sprintf("$s\n",'blabla');
> echo sprintf("$s1\n",'blabla');
> ?>
>
>
> Thanks,
> Andreas
>
>
> --
> PHP 3 Mailing List <http://www.php.net/>
> To unsubscribe, send an empty message to php3-unsubscribe <email protected>
> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
> To search the mailing list archive, go to:
http://www.php.net/mailsearch.php3
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Leon Mergen: "Re: [PHP3] Re: [[PHP3] SMS]"
- Previous message: Gunnar Kristjansson: "[PHP3] How Can I cut "<" and ">""
- In reply to: Andreas Jung: "[PHP3] Variable substitution in sprintf() format string ?!"
- Next in thread: Andreas Jung: "Re: [PHP3] Variable substitution in sprintf() format string ?!"
- Reply: Andreas Jung: "Re: [PHP3] Variable substitution in sprintf() format string ?!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

