我刚刚写了一个简单的PHP脚本,我有一些非常奇怪的行为.我把它减少到重新创建bug所需的最小值:
<?php
$arr = array("foo",
"bar",
"baz");
foreach ($arr as &$item) { /* do nothing by reference */ }
print_r($arr);
foreach ($arr as $item) { /* do nothing by value */ }
print_r($arr); // $arr has changed....why?
?>
Run Code Online (Sandbox Code Playgroud)
这输出:
Array
(
[0] => foo
[1] => bar
[2] => baz
)
Array
(
[0] => foo
[1] => bar
[2] => bar
)
Run Code Online (Sandbox Code Playgroud)
这是一个错误还是一些应该发生的奇怪行为?
我正在建立一个个人股票平台(未分发).我想要的组件是此页面上的EPS图表:
正如你所看到的那样,页面是https这样的,所以经过几天的讨论后,我启用了openssl,现在它似乎适用于所有https页面,例如facebook和twitter的主页,但它仍然不能用于我需要的那个.
file_get_contents('https://facebook.com'); /* works */
file_get_contents('https://twittercom'); /* works */
file_get_contents('https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?stockspage=earnings&symbols=AAPL&showPriceLine=yes');
Run Code Online (Sandbox Code Playgroud)
我收到了警告:
Warning: file_get_contents(): SSL: crypto enabling timeout in C:\xampp\htdocs\index.php on line 3
Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\index.php on line 3
Warning: file_get_contents(https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?stockspage=earnings&symbols=AAPL&showPriceLine=yes): failed to open stream: operation failed in C:\xampp\htdocs\index.php on line 3
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\index.php on line 3
Run Code Online (Sandbox Code Playgroud)
我能看到的唯一区别是保真度页面在https标签附近有一个三角形.

如何添加热键来查看lint错误?它告诉我有一个错误,但不告诉我它是什么.如果我想看到我必须犯的错误
右键单击 - > Anaconda - >显示错误列表
这似乎很不方便.我认为最好在底部有一个面板,显示所有lint错误,或者至少添加一个热键来切换错误菜单.
我正在构建自己的折线图,并希望知道如何<path>在悬停时进行线交互.
例如(简化):
<path d="M5,10L10,20L30,40"></path>
Run Code Online (Sandbox Code Playgroud)
当用户将鼠标悬停在5,10或10,20显示<circle>或仅显示命令时,我将如何执行悬停事件?有什么东西我缺少或者我必须检测鼠标的位置吗?
我有一个带有调用其他方法的方法的类:
class MyClass {
build(methods) {
methods.forEach((method) => {
if (this.method) {
this.method();
}
});
}
stuff() {}
moreStuff() {}
}
const a = MyClass();
a.build(['stuff', 'moreStuff']);
Run Code Online (Sandbox Code Playgroud)
我找不到任何关于类的特殊方法的参考。我的第一个想法是使用 hasOwnProperty (但是 eslint 唠叨我不应该在课堂上使用它)。由于类具有内置函数,因此上述方法无法可靠地工作。
我也认为Reflect可能是我的救星,但我真的可以使用一些指导来说明这种情况下的最佳实践是什么?
我正在使用正则表达式的困难时期,我得到一个单独的"收入",没有任何以前的匹配.
$string = "FY2013 EPS, FQ 2012 revenue";
preg_match_all("/F[Y|Q]\s?\d{4}\sEPS|revenue/", $string, $matches);
print_r($matches);
Run Code Online (Sandbox Code Playgroud)
结果:
Array ( [0] => Array ( [0] => FY2013 EPS [1] => revenue ) )
Run Code Online (Sandbox Code Playgroud)
我期待的是:
Array ( [0] => Array ( [0] => FY2013 EPS [1] => FQ 2012 revenue ) )
Run Code Online (Sandbox Code Playgroud) 我试图将数字四舍五入到前两位数.
14300 -> 15000
1430 -> 1500
143 -> 150
14 -> 14
Run Code Online (Sandbox Code Playgroud)
我弄清楚了这一点:
var n = 14300;
n = parseFloat(Math.ceil(n).toPrecision(2));
console.log(n);
Run Code Online (Sandbox Code Playgroud)
它返回14000,但我想将它四舍五入.Math.ceil仅适用于下一个整数. http://jsfiddle.net/cruTY/
注意:我知道我可以除以n使其成为小数,但我希望此函数适用于所有数字,而无需手动插入/1000或/1000000.
我想知道通过DOMDocument创建html元素是否是"不好的做法".下面是一个在我的内部构建元标记的函数<head>:
$head = new DOMDocument();
foreach($meta as $meta_item) {
$meta_element = $head->createElement('meta');
foreach($meta_item as $k=>$v) {
$attr = $head->createAttribute($k);
$attr->value = $v;
$meta_element->appendChild($attr);
}
echo($head->saveXML($meta_element));
}
Run Code Online (Sandbox Code Playgroud)
与:
foreach($meta as $meta_item) {
$attr = '';
foreach($meta_item as $k=>$v) {
$attr .= ' ' . $k . '="' . $v . '"';
}
?><meta <?php echo $attr; ?>><?php
}
Run Code Online (Sandbox Code Playgroud)
就成本而言,在测试时,它似乎是微不足道的.我的问题:我不应该养成这样做的习惯吗?这是一个前进的坏主意吗?
我正在尝试使用Python 3.4.3和pip在Debian上设置服务器.
我从源代码安装python 3.4.3到/ opt目录(是正确的安装到?).我将/ bin导出到路径中
export PATH="$PATH:/opt/python3.4.3/bin"
Run Code Online (Sandbox Code Playgroud)
但是当我关闭ssh时,当我重新登录时它不起作用.
并且没有脚本文件夹...所以pip在哪里?
我试图在使用时包括分隔符preg_split但是没有成功.
print_r(preg_split('/((?:fy)[.]+)/', 'fy13 eps fy14 rev', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
Run Code Online (Sandbox Code Playgroud)
我想回来:
array(
[0] => fy13 eps
[1] => fy14 rev
)
Run Code Online (Sandbox Code Playgroud)
将flags参数设置为PREG_SPLIT_DELIM_CAPTURE:
如果设置了此标志,则将捕获并返回分隔符模式中的带括号的表达式.
的fy是括号,所以我不知道为什么这是行不通的.
php ×5
regex ×2
apache ×1
arrays ×1
debian ×1
domdocument ×1
ecmascript-6 ×1
javascript ×1
linux ×1
loops ×1
openssl ×1
python ×1
reference ×1
sublimetext ×1
sublimetext3 ×1
svg ×1