我有一个值,可以是图像 URL 或图像 Base64 字符串。确定哪个是哪个的最佳方法是什么?如果它是图像 URL,则图像将已驻留在我的服务器上。
我试过做一个 preg_match 但我认为在一个潜在的巨大 base64 字符串上运行一个 preg_match 将是服务器密集。
编辑:迄今为止的两种最佳方法。
// if not base64 URL
if (substr($str, 0, 5) !== 'data:') {}
// if file exists
if (file_exists($str)) {}
Run Code Online (Sandbox Code Playgroud) 我想将以下内容重写为 HTML 模式:
if (/\S/.test(myString)) {
// string is not empty and not just whitespace
}
Run Code Online (Sandbox Code Playgroud)
所以
<input pattern="\S" required">
if ($('form :invalid'))
console.log('empty');
else
console.log('has non-whitespace char');
Run Code Online (Sandbox Code Playgroud)
问题是我的模式与测试字符串的工作方式不同。我想检查是否至少有 1 个非空白字符。
我试图强制 li.key 不换行到新列。我想要一个新的 li.key 从每列的顶部开始。这是一个 JS 小提琴。
不使用JS可以实现吗?
<ol class="columns">
<li class="key">A
<ol>
<li>Alcoholic beverage, wine, table, white, Fume Blanc</li>
<li>Alcoholic Beverage, wine, table, red, Cabernet Franc</li>
<li>Apples, raw, red delicious, with skin</li>
</ol>
</li>
<li class="key">B
<ol>
<li>Buckwheat groats, roasted, dry</li>
<li>Babyfood, vegetables, carrots, junior</li>
<li>Beef, round, knuckle, tip center, steak, separable lean and fat, trimmed to 0" fat, all grades, raw</li>
<li>Bagels, plain, unenriched, with calcium propionate (includes onion, poppy, sesame)</li>
<li>Babyfood, juice, mixed fruit</li>
<li>Beef, short …Run Code Online (Sandbox Code Playgroud) 我想匹配字符串中的文本,同时忽略它的字母大小写。如果字母大小写不相同,我的示例就会失败。
/*
$text: fOoBaR
$str: little brown Foobar
return: little brown <strong>Foobar</strong>
*/
function bold($text, $str) {
// This fails to match if the letter cases are not the same
// Note: I do not want to change the returned $str letter case.
return preg_replace('/('.str_replace(array("/", "\\"), array("\/", "\\"), $text).')/', "<strong>$1</strong>", $str);
}
$phrase = [
'little brown Foobar' => 'fOoBaR',
'slash / slash' => 'h / sl',
'spoon' => 'oO',
'capital' => 'CAPITAL',
];
foreach($phrase as $str => $text)
echo …Run Code Online (Sandbox Code Playgroud) 我怎样才能将self $(this)参数传递给d3选择器?
function d3_bar(self, dataset, barPadding) {
var w = parseInt(d3.select(".barChart").style("width"),10), // select(self)
h = parseInt(d3.select(".barChart").style("height"),10); // select(self)
var svg = d3.select(".barChart") // select(self)
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", function(d, i) {
return i * (w / dataset.length);
})
.attr("y", function(d) {
return h - (d * 4);
})
.attr("width", w / dataset.length - barPadding)
.attr("height", function(d) {
return d * 4;
})
.attr("fill", function(d) {
return "rgb(0, 0, " + (d * …Run Code Online (Sandbox Code Playgroud) 我想用渐变填充这个折线图的区域,这样渐变的底部是透明的,区域填充的顶部是黑色的。这可能吗?
我所有的谷歌搜索都显示了如下图表:http : //bl.ocks.org/d3noob/4433087 - 我不希望渐变基于值,在这个例子中,我希望顶部有红色面积,而不仅仅是当值达到该百分比时。
var entries = [{"date":"2016-01-06","value":15},{"date":"2015-11-17","value":15.4},{"date":"2015-11-11","value":16.5},{"date":"2015-09-24","value":15.1},{"date":"2015-08-22","value":15},{"date":"2015-08-12","value":15},{"date":"2015-07-30","value":14.6},{"date":"2015-07-19","value":14.8},{"date":"2015-07-18","value":14.9},{"date":"2015-07-12","value":14.9},{"date":"2015-07-08","value":14.9},{"date":"2015-06-29","value":14.3},{"date":"2015-06-21","value":14.5},{"date":"2015-06-18","value":14.7},{"date":"2015-06-09","value":15},{"date":"2015-06-08","value":14.1},{"date":"2014-12-06","value":13.4},{"date":"2014-09-10","value":13.1},{"date":"2014-08-01","value":14.2},{"date":"2014-07-07","value":15},{"date":"2014-05-31","value":14},{"date":"2014-05-24","value":15},{"date":"2014-05-14","value":15},{"date":"2014-05-13","value":14},{"date":"2014-05-08","value":14.5},{"date":"2014-05-02","value":15}];
var margin = {top: 30, right: 20, bottom: 30, left: 50},
overlayW = $('.chart').innerWidth(),
overlayH = $('.chart').innerHeight(),
width = overlayW,
height = 250 - margin.top - margin.bottom,
parseDate = d3.time.format("%Y-%m-%d").parse,
bisectDate = d3.bisector(function(d) { return d.date; }).left,
formatValue = d3.format(",.2f");
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.tickSize(0)
.tickValues(x.domain())
.orient("bottom")
.tickFormat(d3.time.format("%b"));
var yAxis = d3.svg.axis()
.scale(y)
.tickSize(0)
.ticks(5)
.orient("left"); …Run Code Online (Sandbox Code Playgroud)我想用数字和字母顺序对UL进行排序,使用每个项目的data-char值.
注意:我只想对父UL进行排序,而不是子UL元素.
<ul>
<li data-char="w">
<span>W</span>
<ul>
<li>WWWWWWWWWWWWWW</li>
</ul>
</li>
<li data-char="5">
<span>5</span>
<ul>
<li>55555555555555</li>
</ul>
</li>
<li data-char="a">
<span>A</span>
<ul>
<li>AAAAAAAAAAAAAA</li>
</ul>
</li>
<li data-char="1">
<span>1</span>
<ul>
<li>11111111111</li>
</ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作,我可以通过jQuery完成此任务:
function sortCharLi(a, b) {
var va = a.dataset.char.toString().charCodeAt(0),
vb = b.dataset.char.toString().charCodeAt(0);
// add weight if it's a number
if (va < 'a'.charCodeAt(0)) va += 100;
if (vb < 'a'.charCodeAt(0)) vb += 100;
return vb < va ? 1 : -1;
}
$('ul > li').sort(sortCharLi).appendTo('ul');
Run Code Online (Sandbox Code Playgroud)
但我需要删除jQuery依赖项,因此不再是一个选项.
有没有想法如何在没有jQuery的情况下做到这一点?
我希望 Markdown 文件忽略下面的代码片段。我怎么能这样做呢?
" highlight ugly code
augroup HighlightUglyCode
autocmd!
autocmd WinEnter,BufEnter * call clearmatches() | call matchadd('ErrorMsg', '\s\+$', 100) | call matchadd('ErrorMsg', '\%>150v.\+', 100)
augroup EN
Run Code Online (Sandbox Code Playgroud)
我尝试做
autocmd FileType md
Run Code Online (Sandbox Code Playgroud)
但根据我的理解,这将针对 .md 文件,而不是排除它们。
有什么建议么?
我想让这个三角形在中间倾斜,并且我不需要任何额外的 HTML。
<span class="dropdown">dropdown</span>
.dropdown:after
{
display: inline-block;
margin-left: 4px;
content: '';
border-top: 5px solid rgba(0,0,0,.2);
border-right: 5px solid transparent;
border-left: 5px solid transparent;
}
Run Code Online (Sandbox Code Playgroud)
期望的结果

我该怎么做?
我想删除尾随的空行(空行也可能只是一堆制表符和空格)。
在我的.vimrc我有:
autocmd BufWritePre * :%s#\($\n\s*\)\+\%$## " trim white spaces at the end of file
Run Code Online (Sandbox Code Playgroud)
这有效,但是如果文件已经删除了其尾随空白行,我会收到以下错误消息:
Error detected while processing BufWrite Auto commands for "*":
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
javascript ×3
css ×2
d3.js ×2
php ×2
vim ×2
base64 ×1
css-shapes ×1
file-type ×1
gradient ×1
html ×1
jquery ×1
preg-replace ×1
regex ×1