Jump to content

printf()


niche

Recommended Posts

I have this code that displays properly:

printf("<p style=\"font-size:9px;margin:0px;\"> <span style=\"background-color:yellow\">Expires %s. </span></p>",$expdat); 

Now, I need to turn the code between in <span> in to a variable with a variable.How do I code for the second variable in printf() when?:$dclaim = <span style=\"background-color:yellow\">Expires' . $expdat . '.</span>

Link to comment
Share on other sites

at JSG's suggestion, I'm working with printf(), as well as, eval() to try to solve my problem. This topic's about printf().When I manually code, I get the proper display based on: printf("<p style=\"font-size:9px;margin:0px;\"> <span style=\"background-color:yellow\">Expires %s. </span></p>",$expdat);Now i need to get the values from the mysql table. So based on the above success, if the <span style=\"background-color:yellow\">Expires %s. </span> value comes from the mysql table, how do I need to change my printf() script and what does the table value need to be (i assume the table value will need to be changed)?

Link to comment
Share on other sites

First, the value in the database should be the exact string, you don't need to escape quotes or anything. You should be getting this value from the database:

$db_val = '<span style="background-color:yellow">Expires %s. </span>';

Second, it doesn't matter where the string comes from, if it's hard-coded or in a database or a file or whatever else. It's just a string. Use it like you would any other string.

$replaced = sprintf($db_val, $expdat);echo $replaced;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...