const [ , path, file ] = /(.+\/)([^\/]+)$/.exec(str);
// или
const i = str.lastIndexOf('/') + 1;
const file = str.slice(i);
const path = str.slice(0, i);
// или
const parts = str.split(/(\/)/);
const file = parts.pop();
const path = parts.join('');
preg_match('~^(.+\/)([^\/]+)$~', $str, $matches);
list($path, $file) = array_slice($matches, 1);
// или
$i = strrpos($str, '/') + 1;
$file = substr($str, $i);
$path = substr($str, 0, $i);
// или
$parts = preg_split('~(?<=\/)~', $str);
$file = array_pop($parts);
$path = implode('', $parts);
<select id="country"></select>
<select id="сity"></select>
<p></p>
const data = {
'Франция': [ 'Париж', 'Марсель', 'Лион' ],
'США': [ 'Вашингтон', 'Чикаго', 'Фарго' ],
'Италия': [ 'Рим', 'Милан', 'Неаполь' ],
};
const country = document.querySelector('#country');
const city = document.querySelector('#сity');
const p = document.querySelector('p');
country.addEventListener('change', e => {
setSelectOptions(city, data[e.target.value]);
});
city.addEventListener('change', () => {
p.innerText = [ country.value, city.value ].join(', ');
});
setSelectOptions(country, Object.keys(data));
function setSelectOptions(selectEl, optionsData) {
selectEl.innerHTML = optionsData.map(n => `<option>${n}</option>`).join('');
selectEl.dispatchEvent(new Event('change'));
}
const cardSelector = '.post';
const buttonSelector = '.post > img';
const menuSelector = '.post-info';
const activeClass = 'active';
document.addEventListener('click', ({ target: t }) => {
if (!t.closest(menuSelector)) {
document.querySelectorAll(menuSelector).forEach(n => n.classList.remove(activeClass));
}
if (t.matches(buttonSelector)) {
t.closest(cardSelector).querySelector(menuSelector).classList.add(activeClass);
}
});
goal-check
выставляется и тут же снимается..goal
и .delete
надо вешать один раз, применяя делегирование:$('.todo-task').on('click', '.delete', function() {
$(this).parent().remove();
});
$('.todo-task').on('click', '.goal', function() {
$(this).toggleClass('goal-check');
});
array_map(function($n) {
return [ "url" => "/site/$n[0]", "label" => $n[1] ];
}, [
[1, 'Главная'],
[2, 'Портфолио'],
[3, 'О нас']
]);
SELECT u.*, COALESCE(v.v_sum, 0) AS total_views
FROM users u
LEFT JOIN (
SELECT f.entity_id, SUM(f.views) AS v_sum
FROM feeds f
GROUP BY f.entity_id
) AS v ON v.entity_id = u.id
ORDER BY v.v_sum DESC
const elements = document.querySelector('#presentation').children;
const className = 'animation';
const delay = 1000;
let i = elements.length - 1;
setInterval(() => {
elements[i].classList.remove(className);
i = (i + 1) % elements.length;
elements[i].classList.add(className);
}, delay);
(function next(i) {
elements.item(i).classList.toggle(className, false);
i = -~i % elements.length;
elements.item(i).classList.toggle(className, true);
setTimeout(next, delay, i);
})(~-elements.length);
const selector = '.tr-class input[type="checkbox"]';
document.querySelectorAll(selector).forEach(function(n) {
n.addEventListener('click', this);
}, e => e.stopPropagation());
for (const n of document.querySelectorAll('.tr-class')) {
n.addEventListener('click', onClick);
}
function onClick(e) {
if (e.target.matches(selector)) {
return;
}
// ...
}
function getRecursiveStr($arr) {
$result = [];
foreach ($arr as $key => $val) {
if (is_array($val)) {
array_push($result, $key, getRecursiveStr($val));
} else {
$result[] = $val;
}
}
return implode(', ', $result);
}
$arr = [
"Один" => [
"Два" => [
"2.87" => [
"2.88",
"2.89"
],
"Три" => [
"Три с половиной",
"Четыре"
]
]
]
];
echo getRecursiveStr($arr); // выведет "Один, Два, 2.87, 2.88, 2.89, Три, Три с половиной, Четыре"
myVariable && (myVariable - 35)
[100, 0, null, '', true, false, 'gdfsg'].map(n => [n ? n - 35 : n, n && (n - 35)]);
/*
0:(2) [65, 65]
1:(2) [0, 0]
2:(2) [null, null]
3:(2) ["", ""]
4:(2) [-34, -34]
5:(2) [false, false]
6:(2) [NaN, NaN]
*/
(n => n && (n - 35))(myVariable)
постоянно возвращает первый кетч
Как решить эту проблему?
moment('06.09.2017 16:16', 'DD-MM-YYYY HH:mm')
new Date('06.09.2017 16:16'.replace(/(\d+)\.(\d+)\.(\d+)/, '$3-$2-$1'))
UPDATE t1
JOIN t2 ON t1.course_name = LEFT(t2.name, LENGTH(t1.course_name))
SET t1.course_id = t2.id;
$('select').val('ru').trigger('click');
пишем так:$('select').val('ru')[0].dispatchEvent(new Event('change'));