Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP语法错误:字符串“后出现意外错误_Php - Fatal编程技术网

PHP语法错误:字符串“后出现意外错误

PHP语法错误:字符串“后出现意外错误,php,Php,我一直在想在这种情况下是否可以添加for循环: $g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')). ($cellContent==null?'mask':'').'">' //if statement

我一直在想在这种情况下是否可以添加for循环:

$g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
                ($cellContent==null?'mask':'').'">'
                //if statement 
                .($this->currentDate === $tutor_date ? 
                    '<div class="inside">'//open inside
                        .'<div class="inside-content">' //open inside-content
                           . '<div class="inside-date">'.$cellContent.'</div>'//open and close inside-date



                             for($i =0; $i < count($appt_date['date']); $i++) {
                               '<div class="inside-event '.$bkg_color.' ck-button btn-xs" title="Group Session">'//open inside-event
                                   . '<label class="label-for-text">'//open label
                                       . '<input type="radio" data-toggle="modal" data-target="#myModal" name="appt_selected" value="'.$tutor_shedule_id.'" >'//open input
                                           . '<span>'.$tutor_info.'</span>' //open and close span
                                       .'</input>'// close input    
                                   . '</label>'// close label
                               . '</div>';//close inside-event
                           }


                           '</div>'//close inside-content
                       . '</div>'//close inside
                . '</td>' //close td


                //else
                : '<div class="inside">'.$cellContent.'</div>'
                  . '</td>' );

  return $g;
我尝试了很多东西,比如加了一个;在for循环的末尾和之前,我还添加了一个。在for循环之前和之后

编辑:

请提供一些反馈意见,让我知道问题出在哪里,而不是否决这个问题。对我来说,这段代码很好,除非你告诉我更好的方法。所以,我非常感谢你的反馈

谢谢

我建议您使用if-else语句而不是这种方法,因为这个过程很难调试。因此,请使用以下代码:

    $g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
            ($cellContent==null?'mask':'').'">';

            if ($this->currentDate === $tutor_date){ 

                $g.='<div class="inside">'//open inside
                    .'<div class="inside-content">' //open inside-content
                       . '<div class="inside-date">'.$cellContent.'</div>';//open and close inside-date



                         for($i =0; $i < count($appt_date['date']); $i++) {
                           $g.='<div class="inside-event '.$bkg_color.' ck-button btn-xs" title="Group Session">'//open inside-event
                               . '<label class="label-for-text">'//open label
                                   . '<input type="radio" data-toggle="modal" data-target="#myModal" name="appt_selected" value="'.$tutor_shedule_id.'" >'//open input
                                       . '<span>'.$tutor_info.'</span>' //open and close span
                                   .'</input>'// close input    
                               . '</label>'// close label
                           . '</div>';//close inside-event
                       }



                      $g.= '</div>'//close inside-content
                   . '</div>'//close inside
            . '</td>' ;//close td

            }else{

             $g.='<div class="inside">'.$cellContent.'</div>'
              . '</td>'; }

  return $g;
我建议您使用if-else语句而不是这种方法,因为这个过程很难调试。因此,请使用以下代码:

    $g = '<td id="'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
            ($cellContent==null?'mask':'').'">';

            if ($this->currentDate === $tutor_date){ 

                $g.='<div class="inside">'//open inside
                    .'<div class="inside-content">' //open inside-content
                       . '<div class="inside-date">'.$cellContent.'</div>';//open and close inside-date



                         for($i =0; $i < count($appt_date['date']); $i++) {
                           $g.='<div class="inside-event '.$bkg_color.' ck-button btn-xs" title="Group Session">'//open inside-event
                               . '<label class="label-for-text">'//open label
                                   . '<input type="radio" data-toggle="modal" data-target="#myModal" name="appt_selected" value="'.$tutor_shedule_id.'" >'//open input
                                       . '<span>'.$tutor_info.'</span>' //open and close span
                                   .'</input>'// close input    
                               . '</label>'// close label
                           . '</div>';//close inside-event
                       }



                      $g.= '</div>'//close inside-content
                   . '</div>'//close inside
            . '</td>' ;//close td

            }else{

             $g.='<div class="inside">'.$cellContent.'</div>'
              . '</td>'; }

  return $g;

好吧,那很痛苦,我试着把它修好一点,至少让它更具可读性。试试这个。。。我还应该指出,我非常确定这段代码容易受到XSS攻击

// Work out the Class names.
$classNameOne = ($cellNumber % 7) == 1 ? ' start '
                                       : ($cellNumber % 7) == 0 ? ' end'
                                                                : ' ';
$classNameTwo = ($cellContent == null) ? 'mask'
                                       : '';
// Build up the html.
$html = '<td id="' . $this->currentDate . '" class="td-top-text ' . $classNameOne .  $classNameTwo . '">';

if ($this->currentDate === $tutor_date) {
    $html .= '<div class="inside">';
    $html .= '<div class="inside-content">';
    $html .= '<div class="inside-date">' . $cellContent . '</div>';

    $dateInstances = count($appt_date['date']);
    for ($i = 0; $i < $dateInstances; $i++) {
        $html .= '<div class="inside-event ' . $bkg_color . ' ck-button btn-xs" title="Group Session">';
        $html .= '<label class="label-for-text">';
        $html .= '<input type="radio" data-toggle="modal" data-target="#myModal~ name="appt_selected" value="'. $tutor_shedule_id .'">';
        $html .= '<span>' . $tutor_info . '</span>';
        $html .= '</input>';
        $html .= '</label>';
        $html .= '</div>';
    }

    $html .= '</div>';
    $html .= '</div>';
    $html .= '</td>';

} else {
    $html .= '<div class="inside">' . $cellContent . '</div>';
    $html .= '</td>';
}

return $html; 

好吧,那很痛苦,我试着把它修好一点,至少让它更具可读性。试试这个。。。我还应该指出,我非常确定这段代码容易受到XSS攻击

// Work out the Class names.
$classNameOne = ($cellNumber % 7) == 1 ? ' start '
                                       : ($cellNumber % 7) == 0 ? ' end'
                                                                : ' ';
$classNameTwo = ($cellContent == null) ? 'mask'
                                       : '';
// Build up the html.
$html = '<td id="' . $this->currentDate . '" class="td-top-text ' . $classNameOne .  $classNameTwo . '">';

if ($this->currentDate === $tutor_date) {
    $html .= '<div class="inside">';
    $html .= '<div class="inside-content">';
    $html .= '<div class="inside-date">' . $cellContent . '</div>';

    $dateInstances = count($appt_date['date']);
    for ($i = 0; $i < $dateInstances; $i++) {
        $html .= '<div class="inside-event ' . $bkg_color . ' ck-button btn-xs" title="Group Session">';
        $html .= '<label class="label-for-text">';
        $html .= '<input type="radio" data-toggle="modal" data-target="#myModal~ name="appt_selected" value="'. $tutor_shedule_id .'">';
        $html .= '<span>' . $tutor_info . '</span>';
        $html .= '</input>';
        $html .= '</label>';
        $html .= '</div>';
    }

    $html .= '</div>';
    $html .= '</div>';
    $html .= '</td>';

} else {
    $html .= '<div class="inside">' . $cellContent . '</div>';
    $html .= '</td>';
}

return $html; 


嗯。。。这段代码乱七八糟。你错过了一次机会;在for语句之前,但也不能像这样连接字符串,特别是如果有一些if/while/for语句…@DonCallisto Hii,请告诉我如何重新编写此代码?我希望看到其他的方法来做到这一点;在for循环之前,我得到一个意外错误:;这是因为你仍然在if语句中。我明白了。。。很好,谢谢你,嗯。。。这段代码乱七八糟。你错过了一次机会;在for语句之前,但也不能像这样连接字符串,特别是如果有一些if/while/for语句…@DonCallisto Hii,请告诉我如何重新编写此代码?我希望看到其他的方法来做到这一点;在for循环之前,我得到一个意外错误:;这是因为你仍然在if语句中。我明白了。。。很好,谢谢你,达曼!我不知道这是这么坏的家伙,我真的很抱歉@ArielMaduro从逻辑上讲,您已经接近得到正确的答案,但是您的布局牺牲了很多可读性,这使得查找错误变得更加困难。三元运算符可能很有用,但在使用它时应该是有选择性的,否则当您返回到代码/调试它时,它会让您感到头疼。我不确定返回的确切上下文,但请记住不要输出,否则可能会有一些讨厌的人破坏东西。我建议您轻松编写代码,但只需在代码文档中使用空格、空行,etc@VirtualPigeon对我得到了正确的数据,我添加for循环只是为了拉出多个事件,我意识到出了问题!丹恩!我不知道这是这么坏的家伙,我真的很抱歉@ArielMaduro从逻辑上讲,您已经接近得到正确的答案,但是您的布局牺牲了很多可读性,这使得查找错误变得更加困难。三元运算符可能很有用,但在使用它时应该是有选择性的,否则当您返回到代码/调试它时,它会让您感到头疼。我不确定返回的确切上下文,但请记住不要输出,否则可能会有一些讨厌的人破坏东西。我建议您轻松编写代码,但只需在代码文档中使用空格、空行,etc@VirtualPigeon对我得到了正确的数据,我添加for循环只是为了拉出多个事件,我意识到出了问题!我会的,我只是想看看是否有人能想出其他的答案……但你是第一个,而且成功了,所以你会是正确的答案;我会的,我只是想看看是否有人能想出其他的答案……但你是第一个,而且成功了,所以你会是正确的答案;