search

Home  >  Q&A  >  body text

colspan=\"$w\" What does this line of code mean?

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

此去经年此去经年2273 days ago1883

reply all(5)I'll reply

  • 秋香姐家的小书童

    秋香姐家的小书童2018-09-15 11:41:55

    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
    0
  • 此去经年

    Thank you, I'll look for splicing again.

    此去经年 · 2018-09-15 11:51:27
  • 此去经年

    此去经年2018-09-14 10:53:09

    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
    0
  • Summer

    $html .= " "; Change it to this $html .= " "; It should work

    Summer · 2018-09-14 12:28:53
    Summer

    "$w" changed to '$w'

    Summer · 2018-09-14 12:29:57
    此去经年

    Changing it to single quotes will also report an error

    此去经年 · 2018-09-15 11:50:04
  • 此去经年

    此去经年2018-09-14 08:14:15

    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>

    reply
    0
  • Cancelreply