# File actionview/lib/action_view/helpers/tag_helper.rb, line 103
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
if block_given?
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
content_tag_string(name, capture(&block), options, escape)
else
content_tag_string(name, content_or_options_with_block, options, escape)
end
end
# File actionview/lib/action_view/helpers/capture_helper.rb, line 36
def capture(*args)
value = nil
buffer = with_output_buffer { value = yield(*args) }
if string = buffer.presence || value and string.is_a?(String)
ERB::Util.html_escape string
end
end
/**
* 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, ''));
});