(3>2)>(1>2)
console.log(1<2<3); //true
console.log(3>2>1); //false
//Скрывать форму для комментариев по умолчанию
function hideCommentFormByDefault() {
let comment_text = document.querySelector('.comment-form__title-text'); //Текст "Написать комментарий" (span)
let editor = document.querySelector('.comment-form_wrapper'); //Редактор плавает между ответами. Это один и тот же элемент всегда.
if (!(comment_text && editor)) return console.log('TC Error: comment_text or editor no found');
let comment_div = comment_text.parentNode;
const CLOSED = 'comment-form__title comment-form__title_listened';
const OPENED = 'comment-form__title';
if (!(comment_div && comment_div.className == OPENED))
return console.log('TC Error: comment form not found!',comment_div && comment_div.className);
let spoiler_status = true; //true means hidden --> we will hide it below
let remove_fn = function() { //any click --> we must show the form
if (!spoiler_status) return;
editor.style.display = '';
comment_text.removeEventListener('click',onclick);
spoiler_status = false;
}
let onclick = function() {
remove_fn();
comment_div.className = OPENED; //Если кликнули по надписи, то нужно также поменять её текст.
}
document.querySelectorAll('.comment__footer-link').forEach(e=>e.addEventListener('click',()=>{ //WTF?? Need neat fix!
remove_fn();
}));
comment_text.addEventListener('click',onclick);
//Меняем стиль текста-кнопки и скрываем редактор
comment_div.className = CLOSED;
editor.style.display = 'none';
}
hideCommentFormByDefault();
<?php
$string = '
<div class="wrap">
<p></p>
<p></p>
<div class="not">
<p></p>
</div>
<p></p>
</div>
<div class="wrap_2">
<p></p>
<p></p>
</div>';
$startPos = 0; //Очередная позиция закрывающего или открывающего тега div
$deep = 0; //Глубина вложенности. Больше 0 нас не интересует.
while (true) {
$pos1 = strpos($string, '<div', $startPos);
$pos2 = strpos($string, '</div>', $startPos);
$mode = $pos1===false?
($pos2===false?0:-1)
:($pos2===false?1:($pos1<$pos2?1:-1));
$startPos = $mode===1?$pos1+1:$pos2+1;
if ($mode===0) break;
elseif ($mode===1) {
if($deep===0) $saveStart = $pos1;
$deep++;
} else { //$mode==-1
$deep--;
if ($deep!==0) continue;
$div = substr($string, $saveStart, $startPos - $saveStart);
echo 'div: ' . preg_match_all('/<p[\s>]/i',$div) . "<br>\n";
}
}
?>
div: 4<br>
div: 2<br>