This doesn't work:
$F = "<div class='f'>F</div>";
$d = "<div class='d'>d</div>";
$Y = "<div class='y'>Y</div>";
$dateFormat = "$F, $d, $Y";
echo date($dateFormat);
This doesn't work:
$F = "<div class='f'>F</div>";
$d = "<div class='d'>d</div>";
$Y = "<div class='y'>Y</div>";
$dateFormat = "$F, $d, $Y";
echo date($dateFormat);
date() will not filter out the HTML tags from the parameter you pass; that is the case of many other PHP functions to which you pass a string containing HTML tags.
The only function that removes HTML tags is strip_tags(). If, for any reason, you are using as parameter of a function a string containing HTML (I don't know in which case it could happen — maybe you are doing something wrong in other parts of the code), you can use the following code, valid for the example you reported.
$F = strip_tags("<div class='f'>F</div>");
$d = strip_tags("<div class='d'>d</div>");
$Y = strip_tags("<div class='y'>Y</div>");
$dateFormat = "$F, $d, $Y";
echo date($dateFormat);
This is the answer to your question. Probably your problem is another one; in that case, the question should have been another one.
I think there are some chances that Sbm007 understood what you meant; the question should have been then
How do I insert HTML tags in a date formatted with
date()?I am trying to format a date mixed in with some HTML. I have tried the following code, but it doesn't work:
$F = strip_tags("<div class='f'>F</div>");
$d = strip_tags("<div class='d'>d</div>");
$Y = strip_tags("<div class='y'>Y</div>");
$dateFormat = "$F, $d, $Y";
echo date($dateFormat);
I'm not sure what you're trying to do. If you just want to format the date mixed in with some HTML then try this:
$formatted_date = sprintf("<div class='f'>%s</div>\n<div class='d'>%u</div>\n<div class='y'>%u</div>", date("F"), date("d"), date("Y"));
echo $formatted_date;