在我用PHP开发的这些年里,我总是听说使用eval()是邪恶的.
考虑以下代码,使用第二个(更优雅)选项是否有意义?如果没有,为什么?
// $type is the result of an SQL statement
// e.g. SHOW COLUMNS FROM a_table LIKE 'a_column';
// hence you can be pretty sure about the consistency
// of your string
$type = "enum('a','b','c')";
// possibility one
$type_1 = preg_replace('#^enum\s*\(\s*\'|\'\s*\)\s*$#', '', $type);
$result = preg_split('#\'\s*,\s*\'#', $type_1);
// possibility two
eval('$result = '.preg_replace('#^enum#','array', $type).';');
Run Code Online (Sandbox Code Playgroud) 让我们假设下表(例如几个内连接语句的结果):
id | column_1 | column_2
------------------------
1 | 1 |
2 | 2 | 2
3 | | 3
Run Code Online (Sandbox Code Playgroud)
例如,您可以从以下语句中获取:
select a.id, t1.column_1, t2.column_2
from a
left join t1 on a.id = t1.id
left join t2 on a.id = t2.id
Run Code Online (Sandbox Code Playgroud)
现在,如果我想总结t1.column_1和t2.column_2,如下所示
select
a.id,
t1.column_1,
t2.column_2,
(t1.column_1 + t2.column_2) as cumulated
from a
left join t1 on a.id = t1.id
left join t2 on a.id = t2.id
Run Code Online (Sandbox Code Playgroud)
reslut将如下所示:
id | column_1 | column_2 | cumulated
------------------------------------
1 | 1 | …Run Code Online (Sandbox Code Playgroud) 在XSLT中包含html实体的最佳方法是什么?
<xsl:template match="/a/node">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
这个返回一个XsltParseError
我需要在JavaScript中使用RSA加密一些数据.周围的所有库都要求指数和模数,但我public.key从对手那里得到一个文件.
如何从RSA文件中检索公共exponent和modulus部分?
在php中,我经常需要使用数组来映射变量......但我似乎无法在一个内联中执行此操作.cf示例:
// the following results in an error:
echo array('a','b','c')[$key];
// this works, using an unnecessary variable:
$variable = array('a','b','c');
echo $variable[$key];
Run Code Online (Sandbox Code Playgroud)
这是一个小问题,但它每隔一段时间就会不停地窃听......我不喜欢这样一个事实:我没有使用变量;)
我有一个问题,我的标签d3.svg.axis有时会重叠.因此,我想将最大量的刻度和标签减少到一定量.
我似乎无法在API文档中找到解决方案.
我不能使用,axis.tickValues()因为范围是动态的,可以从几个小时到几年.
我尝试过使用axis.ticks(9)但似乎没有效果.你可以看看bl.ocks.org/3181719上的一个例子.
说我有这个给定的xml文件
<root>
<node>x</node>
<node>y</node>
<node>a</node>
</root>
Run Code Online (Sandbox Code Playgroud)
我想要显示以下内容
ayx
Run Code Online (Sandbox Code Playgroud)
使用类似的东西
<xsl:template match="/">
<xsl:apply-templates select="root/node"/>
</xsl:template>
<xsl:template match="node">
<xsl:value-of select="."/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud) 此代码适用于我尝试过的所有其他浏览器,IE8除外.
IE8似乎忽略了z-index - 弹出窗口变成了pop-under.
它位于正确的位置,只是缩略图下方的渲染.
任何人?
谢谢!
HTML:
<a class="thumbnail" href="#thumb">
<img src="comic_a3_thumb.jpg" height="300" width="212" border="0"
style="float:right; margin-top:10px;margin-bottom:10px;"
alt="description" />
<span>
<img src="/images/comic_a3_popup.jpg" />
</span>
</a>
Run Code Online (Sandbox Code Playgroud)
CSS:
.thumbnail{
position: relative;
z-index: 0;
}
.thumbnail:hover{
background-color: transparent;
z-index: 50;
}
.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: lightyellow;
padding: 5px;
left: 0px;
border: 1px dashed gray;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}
.thumbnail:hover span{ /*CSS for …Run Code Online (Sandbox Code Playgroud) 给出以下XML:
<current>
<login_name>jd</login_name>
</current>
<people>
<person>
<first>John</first>
<last>Doe</last>
<login_name>jd</login_name>
</preson>
<person>
<first>Pierre</first>
<last>Spring</last>
<login_name>ps</login_name>
</preson>
</people>
Run Code Online (Sandbox Code Playgroud)
如何从当前/登录匹配器中获取"John Doe"?
我尝试了以下方法:
<xsl:template match="current/login_name">
<xsl:value-of select="../people/first[login_name = .]"/>
<xsl:text> </xsl:text>
<xsl:value-of select="../people/last[login_name = .]"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud) 尝试在mysql中创建存储过程时,我很难找到错误.
如果我独立运行程序的每一行,一切正常.
CREATE PROCEDURE cms_proc_add_child
(
param_parent_id INT, param_name CHAR(255),
param_content_type CHAR(255)
)
BEGIN
SELECT @child_left := rgt FROM cms_tree WHERE id = param_parent_id;
UPDATE cms_tree SET rgt = rgt+2 WHERE rgt >= @child_left;
UPDATE cms_tree SET lft = lft+2 WHERE lft >= @child_left;
INSERT INTO cms_tree (name, lft, rgt, content_type) VALUES
(
param_name,
@child_left,
@child_left+1,
param_content_type
);
END
Run Code Online (Sandbox Code Playgroud)
我得到以下(有用)错误:
错误1064(42000):您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第3行的"'附近使用正确的语法
我只是不知道从哪里开始调试,因为这些行中的每一行都是正确的.
你有什么建议吗?