Пример #1
0
function displayComment(array $comments, $seporator = '[endOfComment]')
{
    global $divStyles;
    global $divStylesBadWords;
    //проверяем, были ли ранее комментарии
    if (count($comments) == 0) {
        echo "<div {$divStyles} >";
        echo 'тут будет отображен Ваш комментарий';
        echo '</div>';
    } else {
        $temp = join('', $comments);
        $comments = explode("{$seporator}", $temp);
        // Тут будет выводиться комментарий
        foreach ($comments as $key => $comment) {
            //если комментарий не пустая строка
            if ($comments[$key]) {
                // проверим его на наличие недопустимыъ слов
                if (checkBadWords($comments[$key]) == false) {
                    echo "<div {$divStyles} >";
                    echo $comments[$key];
                    echo '</div>';
                } else {
                    echo "<div {$divStylesBadWords} >";
                    echo 'В вашем комментарии есть недопутсимые слова. Быдло детектед';
                    echo '</div>';
                }
            }
        }
    }
}
        return false;
    }
    return true;
}
if (sizeof($_POST)) {
    if (isset($_POST['username']) && isset($_POST['text'])) {
        if (!empty($_POST['username'] || !empty($_POST['text']))) {
            $userName = trim(strip_tags($_POST['username']));
            $text = trim(htmlspecialchars($_POST['text']));
            $text = str_replace('&lt;b&gt;', '<b>', $text);
            $text = str_replace('&lt;/b&gt;', '</b>', $text);
            if (preg_match_all('|<b>|', $text) && !preg_match_all('|</b>|', $text)) {
                $text .= '</b>';
            }
            $text = nl2br($text);
            if (checkBadWords($text)) {
                $dataArr = ['username' => $userName, 'text' => $text, 'date' => date('Y-M-d H:m:s')];
                saveText($path, $dataArr);
            } else {
                $alert = 'Некорректный комментарий';
            }
        } else {
            $alert = 'Заполните все поля';
        }
    }
}
?>

<!doctype html>
<html lang="en">
<head>