Hi. I have this simple code:
=============== =============== =============
->Database query here
(.. some code)
$row=mysql_fetc h_array($res);
(...)
$formatting2 = $row['formatting2"];
(..)
//Echo variable from DB
echo "$formattin g2";
$formatting2 = "USERNAME: %1\$s \r\nSERIAL: %2\$s \r\n\r\n";
//Echo same string - this time from an "inline" variable
echo "$formattin g2";
=============== =============== =============
Ok, maybe that was overly complicated. I hope you follow anyway. Whats
happening here is that I am getting a formatted string from a database
which I throw in a variable. What you see here is my test case to
visualize the problem. Now, when I echo this variable or pass it to
printf/sprintf then I get a different result than if I "manually"
create the variable inline in my php script.
So, the first echo $formatting2 there will output:
USERNAME: %1$s \r\nSERIAL: %2$s \r\n\r\n
whilst the second shows the newlines correctly. Also printf/sprintf
barfs if I pass the string I got from the DB.
What the heck is going on here? Database returning some strange string
format?
Thanks :)
Arni Johannesson
=============== =============== =============
->Database query here
(.. some code)
$row=mysql_fetc h_array($res);
(...)
$formatting2 = $row['formatting2"];
(..)
//Echo variable from DB
echo "$formattin g2";
$formatting2 = "USERNAME: %1\$s \r\nSERIAL: %2\$s \r\n\r\n";
//Echo same string - this time from an "inline" variable
echo "$formattin g2";
=============== =============== =============
Ok, maybe that was overly complicated. I hope you follow anyway. Whats
happening here is that I am getting a formatted string from a database
which I throw in a variable. What you see here is my test case to
visualize the problem. Now, when I echo this variable or pass it to
printf/sprintf then I get a different result than if I "manually"
create the variable inline in my php script.
So, the first echo $formatting2 there will output:
USERNAME: %1$s \r\nSERIAL: %2$s \r\n\r\n
whilst the second shows the newlines correctly. Also printf/sprintf
barfs if I pass the string I got from the DB.
What the heck is going on here? Database returning some strange string
format?
Thanks :)
Arni Johannesson
Comment