/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
*/
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
}
// $range is in IP/CIDR format eg 127.0.0.1/24
list( $range, $netmask ) = explode( '/', $range, 2 );
$range_decimal = ip2long( $range );
$ip_decimal = ip2long( $ip );
$wildcard_decimal = pow( 2, ( 32 - $netmask ) ) - 1;
$netmask_decimal = ~ $wildcard_decimal;
return ( ( $ip_decimal & $netmask_decimal ) == ( $range_decimal & $netmask_decimal ) );
}
jQuery(function ($) {
var $doc = $(document);
var isDown = false;
$doc.on('mousedown', function () {
isDown = true;
});
$doc.on('mouseup', function () {
isDown = false;
});
$doc.on('keypress', function (event) {
if (isDown) {
console.log(
'pressed via mousedown',
event.which
);
}
});
});
<?php
$html = <<<EOF
<img height="720" src="http://www.example.com/static/ckef/img/2_122.jpg" width="960">
<img height="720" src="http://www.example.com/static/ckef/img/2_122.jpg" width="960">
<img height="720" src="http://www.example.com/static/ckef/img/2_122.jpg" width="960">
EOF;
$dom = new DOMDocument();
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');
$result = '';
/** @var DOMElement $image */
foreach ($images as $image) {
$image->removeAttribute('width');
$image->removeAttribute('height');
$result .= $dom->saveHTML($image);
}
echo $result, PHP_EOL;
<img src="http://www.example.com/static/ckef/img/2_122.jpg"><img src="http://www.example.com/static/ckef/img/2_122.jpg"><img src="http://www.example.com/static/ckef/img/2_122.jpg">
var re = /(?:^https?:\/\/(?:www\.)?)|(?:\/$)/g;
var strings = [
'http://foo.bar',
'http://foo.bar/',
'http://www.foo.bar',
'http://www.foo.bar/',
'https://foo.bar',
'https://foo.bar/',
'https://www.foo.bar',
'https://www.foo.bar/'
];
strings.forEach(function (string) {
console.log(string.replace(re, ''));
});
php > preg_match('/wall-(\d+)_(\d+)/', 'https://vk.com/wall-1234567_890', $matches);
php > var_dump($matches);
array(3) {
[0]=>
string(16) "wall-1234567_890"
[1]=>
string(7) "1234567"
[2]=>
string(3) "890"
}
list(, $post_id, $owner_id) = $matches;
<?php
preg_match('/wall-(\d+)_(\d+)/', 'wall-1234567_890', $matches);
list(, $post_id, $owner_id) = $matches;
var_dump($post_id, $owner_id);