$patterns = [
['regexp' => '/JFIF/', 'type' => 'picture'],
...
];
$types = [
'picture' => 0,
...
]
foreach ($pattenrs as $pattern) {
if (checkPattern($file, $pattern['regexp']) {
$types[$pattern['type']] += 1;
}
}
$detectedType = null;
$detectedMax = 0;
foreach ($types as $type => $value) {
if ($value > $detectedMax) {
$detectedMax = $value;
$detectedType = $type;
}
}
const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_COMMENT,
{
acceptNode: (node) => {
if (/^\s*comment/.test(node.data)) {
return NodeFilter.FILTER_ACCEPT
}
return NodeFilter.FILTER_REJECT
}
}
)
let node = treeWalker.nextNode()
let span
let text
while (node) {
span = document.createElement('span')
text = node.nextSibling
span.innerText = text.data
text.parentNode.replaceChild(span, text)
node = treeWalker.nextNode()
}
$arr = json_decode($json, true);
$id = 0;
$newJson = json_encode([
'total' => count($arr),
'totalNotFiltered ' => count($arr),
'rows' => array_map(
function ($uid, $el) use (&$id) {
$el['uid'] = $uid;
$el['id'] = $id++;
return $el;
},
array_keys($arr),
array_values($arr)
)
]);