yum update
'\u00ad'
uasort($Array, function($first, $second) {
if ($first->p == $second->p) {
return 0;
}
return ($first->p < $second->p) ? 1 : -1;
});
<?php
$dom = new DOMDocument();
$dom->loadXML('
<div class="abc">
<span class="foo">Hello</span>
<span class="bar">World</span>
<span class="baz">by</span>
</div>');
$xpath = new DOMXPath($dom);
$result = $xpath->evaluate('concat(/div/span[@class="foo"]/following-sibling::*[1], " ", /div/span[@class="foo"]/following-sibling::*[2])');
var_dump($result);
string 'World by' (length=8)
foreach ($xpath->query('//a/@href') as $href) {
echo $href->nodeValue, PHP_EOL;
}
https://3v4l.org/0XlvA <?php
$XMLResult = '
<root>
<a href="https://google.com/">google.com</a>
<a href="https://bing.com/">bing.com</a>
<a href="https://yahoo.com/">yahoo.com</a>
</root>';
$XML = simplexml_load_string($XMLResult);
$XMLResults = $XML->xpath('/root/a/@href');
foreach($XMLResults as $SimpleXMLElement) {
var_dump(strval($SimpleXMLElement['href']));
}
string 'https://google.com/' (length=19)
string 'https://bing.com/' (length=17)
string 'https://yahoo.com/' (length=18)
$var = $var / 5;
const hashes = [ DIV:1, P:1, SPAN:1, ... ];
if (hashes[el.nextSibling.nodeName]) {
...
if (element.previousSibling) {
// ... остальной код Дмитрия Дерепко
}
// Или без вложенных циклов
// сначала проверить: если у элемента нет предшествующего элемента
if (!element.previousSibling) {
return element;
// вернуть элемент, чтобы другая функция что-то с ним могла сделать.
// Или вернуть false, не суть. Важно просто обработать сценарий, когда элемент
// идет первым в родителе. Можно просто выйти из функции.
}
// Дальше, если предшественник есть, делаем как в коде Дмитрия
const targetTags = ['h1', 'h2', ...],
lowerName = element.previousSibling.nodeName.toLowerCase();
if (!targetTags.includes(lowerName)) {
// do samething
}
// Кстати, можно targetTags передавать сразу аргументом в функцию, чтобы код был чуть
// более универсальным.
function doSomethingEpic(element, targetTargs) {
// code
}
const someElem = document.querySelector('.epicElement');
const tags = ['h1', 'h2', ...],
doSomethingEpic(someElement, tags);
if (element.previousSibling !== null) {
const lowerName = element.previousSibling.nodeName.toLowerCase();
const tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'img'];
if (!tags.includes(lowerName) {
// ...
}
}
const tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'img'];
if (element.previousSibling !== null && !tags.includes(element.previousSibling.nodeName.toLowerCase())) {
// ...
}