colspan=\"$w\" What does this line of code mean?
此去经年
此去经年 2018-09-14 07:49:28
0
5
1879

if ($w && $d == 1) { // If the first day of the month is not a Sunday, fill in the blanks
$html .= "<td colspan=\"$w\"> ; </td>";
                                                                                                  

此去经年
此去经年

reply all(3)
秋香姐家的小书童

It is not recommended to write this, you’d better write it like this

if ($w && $d == 1) {                // 如果该月的第1天不是星期日,则填充空白
   $html .= "<td colspan=".$w."> </td>";
}

I suggest you learn more about string splicing methods and efficiency issues

  • reply Thank you, I'll look for splicing again.
    此去经年 author 2018-09-15 11:51:27
此去经年

Found it, it is an escape character. But why can’t we directly $html .= "<td colspan="$w"> </td>";

I know an error will be reported

Parse error: syntax error, unexpected '$w' (T_VARIABLE) in /home/phpcn6peh2pwcun/wwwroot/compile.php(41) : eval()'d code on line 39



Require $html .= "<td colspan=\"$w\"> </td>";

But why is this?

  • reply $html .= "<td colspan="$w"> </td>"; Change it to this $html .= "<td colspan='$w'> </td>"; It should work
    Summer author 2018-09-14 12:28:53
  • reply "$w" changed to '$w'
    Summer author 2018-09-14 12:29:57
  • reply Changing it to single quotes will also report an error
    此去经年 author 2018-09-15 11:50:04
此去经年

This is the complete code. I don’t understand what the backslash in line 39 means. Can you help me explain it?

<!doctype html>

<html>
<head>
<title>Make an annual calendar</title>
<style>
// body{text-align:center;}
. box{margin:0 auto;width:880px;}
.title{background:#ccc;}
table{height:200px;width:200px;font-size:12px;text-align:center;float :left;margin:10px;font-family:arial;}
</style>
</head>
<body>
<?php
function calendar( $y)//// 1. Define the almanac generation function
{
// 3. Get the week value of January 1st of the specified year
$w = date('w', strtotime("$y- 1-1"));

$html = '<div class="box">';

// 2. Splice the table for each month
for ( $m = 1; $m <= 12; ++$m) {
          $html .= '<table>';
              $html .= '<tr class="title"> <th colspan="7">' . $y . 'Year' . $m . 'Month</td></tr>';
                $html .= '<tr>< td>Day</td><td>One</td><td>Two</td><td>Three</td><td>Four</td>< td>五</td><td>Six</td></tr>';

// Get the number of days in the current month $m
t', strtotime("$y-$m"));
// Loop from the first day of the month to the last day
for ($d = 1; $d <= $max; ++$d) {
                                                                                                                                                                                                            . #                                                                                                                                                                                                                                  
if ($w && $d == 1) { // If the first day of the month is not a Sunday, fill in the blanks
$html .= "<td colspan=\"$w\"> </td>";
                                                                                                                                                        ##                                                                                                                                                                                                                                                                       
              } elseif ($d == $max) {                                                                                                                                                                                                          $w = ($w + 1 > 6) ? 0 : $w + 1;
                                                                          $html .=                                                                            html .= '</div>';
return $html;
}
echo calendar('2017');
?>
</body>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template