我想有条件地输出HTML来生成一个页面,那么在PHP 4+中回显多行HTML片段的最简单方法是什么?我需要使用像Smarty这样的模板框架吗?
echo '<html>', "\n"; // I'm sure there's a better way!
echo '<head>', "\n";
echo '</head>', "\n";
echo '<body>', "\n";
echo '</body>', "\n";
echo '</html>', "\n";
Run Code Online (Sandbox Code Playgroud) 所以我在smarty中有一个指定的变量:
{assign var=number value=0}
Run Code Online (Sandbox Code Playgroud)
现在我可以使用它来增加它
{$number++}
Run Code Online (Sandbox Code Playgroud)
要么
{++$number}
Run Code Online (Sandbox Code Playgroud)
这正是我需要的,唯一的问题是,它在页面上显示$ number的值.有没有办法可以增加值但不显示它?
这不是在循环内部使用,否则我会使用迭代或索引之类的东西.
我在这个函数式编程和流程方面有点绿色,但我知道的一点点非常有用!
我已经多次出现这种情况了:
List<SomeProperty> distinctProperties = someList.stream()
.map(obj -> obj.getSomeProperty())
.distinct()
.collect(Collectors.toList());
if (distinctProperties.size() == 1) {
SomeProperty commonProperty = distinctProperties.get(0);
// take some action knowing that all share this common property
}
Run Code Online (Sandbox Code Playgroud)
我真正想要的是:
Optional<SomeProperty> universalCommonProperty = someList.stream()
.map(obj -> obj.getSomeProperty())
.distinct()
.collect(Collectors.singleOrEmpty());
Run Code Online (Sandbox Code Playgroud)
我认为singleOrEmpty
除了与之相结合之外,这个东西在其他情况下也很有用distinct
.当我是一个超级n00b时,我花了很多时间重新发明Java Collections Framework,因为我不知道它在那里,所以我不想重复我的错误.Java是否有一个很好的方法来做这singleOrEmpty
件事?我错误地制定了它吗?
谢谢!
编辑:这是distinct
案例的一些示例数据.如果您忽略该map
步骤:
Optional<SomeProperty> universalCommonProperty = someList.stream()
.map(obj -> obj.getSomeProperty())
.distinct()
.collect(Collectors.singleOrEmpty());
[] -> Optional.empty()
[1] -> Optional.of(1)
[1, 1] -> Optional.of(1)
[2, 2] -> Optional.of(2) …
Run Code Online (Sandbox Code Playgroud) 我有这个未被捕获的referenceerror函数未定义错误哪些不明白.
如果我有
$(document).ready(function(){
function codeAddress() {
var address = document.getElementById("formatedAddress").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
和
<input type="image" src="btn.png" alt="" onclick="codeAddress()" />
<input type="text" name="formatedAddress" id="formatedAddress" value="" />
Run Code Online (Sandbox Code Playgroud)
当我按下按钮时,它将返回"未捕获的参考错误".
但是如果我把codeAddress()放在 $(document).ready(function(){}之外,那么它运行正常.
我的意图是将codeAddress()放在document.ready.function中.
我已经安装了干净的Mac OSX Yosemite,但我无法配置Apache 2.4,就像我一直在较旧的OSX版本上做的那样.
这是我想要做的:将"localhost"目录设置为"/ Users/username/Public /".但是,我尝试的一切都行不通,我总是得到一个"Forbiden,无法访问/"或者我得到默认的"它有效!" 页...
如何简单地重新连接我的本地主机?
谢谢
编辑(感谢Krister Andersson的答案)
适用于Mac OSX 10.10 Yosemite
我还发布了我必须做的改变以保持运行.
在"/ etc/apache2/users /"中,我创建了一个由我的用户名命名的文件,如"myUsername.conf".
您可以在终端输入"id"来获取用户名.您应该在"uid = 501(myUsername)"中找到您的用户名.
在这个新的"myUsername.conf"文件中,只需复制过去:
<Directory "/Users/myUsername/Sites/">
AllowOverride All
Options Indexes MultiViews
Options +FollowSymLinks
Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)
不要原谅改变myUsername
价值.
然后,在"/etc/apache2/httpd.conf"文件中,取消注释所有这两行:
167 #LoadModule userdir_module libexec/apache2/mod_userdir.so
169 #LoadModule php5_module libexec/apache2/libphp5.so
Run Code Online (Sandbox Code Playgroud)
第236行,将"DocumentRoot"的目录更改为您想要的任何内容.第250行,将"选项"设置为"选项"选项索引FollowSymLinks Multiviews".第258行,将"AllowOverride None"设置为"AllowOverride All".第263行,将"Require all denied"设置为"Require all granted"
在终端中,键入"sudo apachectl restart"重新启动apache.
它适用于Mac OS X 10.10优胜美地清洁安装.
我听说Git
,你可以local branch A
跟踪另一个local branch B
.
为什么有人想这样做?
我需要获取Windows系统上所有进程的列表,包括名称和PID.
EnumProcess可以获取pid列表,但是如何从pid获取进程名称?我不想在进程上调用OpenProcess,因为它并不总是有效(就好像其他进程是由不同的用户运行).
我通过ProcessStartInfo和process.Start()启动控制台应用程序.我想隐藏黑色的窗户.这是我的代码:
string output = "";
//Setup the Process with the ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\WINNT\\system32\\cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
//Start the process
Process proc = Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud) 我得到一个"对象不支持此属性或方法错误",有谁知道为什么?
我确实将值插入到userId,fname,lname,oname,sam,hasAccess中
function Employee(id, fname, lname, oname, sam, access) {
this.id = id;
this.fname = fname;
this.lname = lname;
this.oname = oname
this.sam = sam;
this.access = access;
}
var emp = new Employee(userId, fname, lname, oname, sam, hasAccess);
var jsonstuff = emp.toSource(); //Breaking here
Run Code Online (Sandbox Code Playgroud)
虽然这个链接说它可能是http://www.w3schools.com/jsref/jsref_toSource_date.asp
我已经搜索了好几个星期来解决我的问题,并找不到一个好的方法,可以在我可能需要使用的每台机器上运行.
我知道START命令会打开一个新窗口来执行.exe,但是我希望保持在同一个窗口并运行.exe
(因为我希望我的批处理文件只在.EXE运行完毕时继续)
我发现在某些计算机上,当我执行.exe时会打开一个新窗口而其他计算机停留在同一个窗口中,这让我觉得我的代码很好但是计算机上的某个地方有不同的设置.
你能帮我吗?我有什么选择?我正在运行的.exe是NASTRAN,它是一个在命令窗口中运行的工程求解器.