Как не создать большой, если список в этой части моего кода? - PullRequest
0 голосов
/ 20 апреля 2020

Я не хочу создавать большой список if для всех глав истории моего сайта.

если $ commentformname [$ a] равно номеру текущей главы, тогда я делаю массив $ commentonchapter1 [$ a], говорящий о том, что комментарий был вставлен в главу 1, главу 2 и т. д.

Так что, если комментарий был опубликован в главе 2, будет создан массив commentonchapter2. .

if ($sitecomments == true) {
    $c = 0;
    $i = 0;
    $z = 0;
    #defines the comment form name, name of who commented, the comment text and time (to be converted, example: 2020-04-09T15:53:07.580Za > 12:53 09/04/2020)
    while ($c <= $commentsnumb) {
        $commentformname[$z] = $comments[$i];
        $i++;

        $commenttername[$z] = $comments[$i];
        $i++;

        $commenttext[$z] = $comments[$i];
        $i++;

        $commenttime[$z] = $comments[$i];
        $i++;

        $c++;
        $z++;
    }

    #shows the text of the comments tab
    echo '<hr class="'.$sitehr2.'" />'."\n";
    echo $divzoomanim.'<'.$n.'><p></p><br /><b>'.$tabnames[7].': '.$orangespan.$commentsnormalnumb.$spanc.' '.$icons[12].'</b><br /><br /><p></p></'.$n.'>'.$divc.'<hr class="'.$sitehr.'" />'."\n";

    $i = 0;
    $z = 0;
    #converts the comment date and time
    #example
    #from 2020-04-09T15:53:07.580Za
    #to 12:53 09/04/2020
    while ($z <= $commentsnumb) {
        $commenttime[$z] = substr($commenttime[$z], 0, -1);
        $commenttime[$z] = date("H:i d/m/Y", strtotime($commenttime[$z]));

        $z++;
    }

    $a = 0;
    $z = 0;
    $i = 0;
    #styles the form name
    #example
    #from "pequenata-comment-7"
    #to '<b>Commented on form "Pequenata-comment-7"</b>'
    while ($a <= $commentsnumb) {
        if ($lang == $langs[0] or $lang == $langs[1]) {
            $commentformname[$i] = '<b>'.$commenttxt3.' '.$commenttxt5.' '.strtolower($formtxt).':</b> "'.ucwords($commentformname[$i]).'"';
        }

        if ($lang == $langs[2]) {
            $commentformname[$i] = '<b>'.$commenttxt3.' '.$commenttxt4.' '.strtolower($formtxt).':</b> "'.ucwords($commentformname[$i]).'"';
        }

        $a++;
        $z++;
        $i++;
    }

    $a = 0;
    $a2 = 1;
    $i = 0;
    $z = 0;
    $c = 0;
    $v = 0;
    $b = 0;
    $commentschapternumb = 0;
    #Generates the array of the website comments
    while ($c <= $commentsnumb) {
        #Generates the comments of the website if the strlen of $commentformname[$a] is equal to 45, String: <b>Commented on form "Pequenata-comment-7"</b>
        if (strlen($commentformname[$a]) == 45) {
            $cmntsgeral[$b] = '<'.$m.' class="'.$textstyle2.'" style="text-align:left;border-width:3px;border-color:'.$bordercolor.';border-style:solid;"><div style="margin-left:5%;margin-right:5%;">'.'<br /><b>'.$a2.' - '.$commenttername[$i].'</b> - '.$commenttime[$i].'<br />'.$commentformname[$i].' '.'<hr class="'.$sitehr3.'" />'.$commenttext[$i].'<br /><br /><br /><br /><br />'.$divc.'</'.$m.'>'."<br />"."\n";
            #Dispalyer disabled because of showing the wrong array (using $z, so it was tring to print a number on the array that didn't existed ($cmntschapter was incrementing on $z)
            #echo $cmntsgeral[$z];

            $a2++;
            $b++;
        }

        #Generates the array of the chapter comments
        if (strlen($commentformname[$a]) == 47) {
            $cmntschapter[$v] = '<'.$m.' class="'.$textstyle2.'" style="text-align:left;border-width:3px;border-color:'.$bordercolor.';border-style:solid;"><div style="margin-left:5%;margin-right:5%;">'.'<br /><b>'.$a2.' - '.$commenttername[$i].'</b> - '.$commenttime[$i].'<br />'.$commentformname[$i].' '.'<hr class="'.$sitehr3.'" />'.$commenttext[$i].'<br /><br /><br /><br /><br />'.$divc.'</'.$m.'>'."<br />"."\n";
            #Doesn't show the chapter comments because they shouldn't be showed in the website comments tab
            #echo $cmntschapter[$z];
            $v++;
            $commentschapternumb++;
        }

        $a++;
        $i++;
        $z++;
        $c++;
    }

    #Shows the website comments on the comments tab of the site
    $z = 0;
    while ($z <= $commentsnormalnumbtowrite) {
        echo $cmntsgeral[$z];

        $z++;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...