正在搜索stackoverflow的解决方案,但找不到任何甚至接近我想要实现的东西.也许我只是幸福地没有意识到每个人都在解决这个问题的一些神奇的PHP酱......;)
基本上我有一个数组,给出或采取几百个网址,指向远程服务器上的不同XML文件.我正在做一些神奇的文件检查,看看XML文件的内容是否已经改变,如果有,我会下载更新的XML到我的服务器.
PHP代码:
$urls = array(
'http://stackoverflow.com/a-really-nice-file.xml',
'http://stackoverflow.com/another-cool-file2.xml'
);
foreach($urls as $url){
set_time_limit(0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, false);
$contents = curl_exec($ch);
curl_close($ch);
file_put_contents($filename, $contents);
}
Run Code Online (Sandbox Code Playgroud)
现在,$ filename被设置在其他地方,并根据我的逻辑为每个xml提供它自己的ID.到目前为止,这个脚本运行正常并且做了应有的事情,但它的速度非常慢.我知道我的服务器可以处理更多,我怀疑我的foreach正在减慢这个过程.
有什么方法可以加速foreach吗?目前我正在考虑将每个foreach循环中的file_put_contents提升到10或20,基本上将我的执行时间缩短10或20倍,但是无法想到如何以最佳和最佳性能方式处理它.有关如何进行的任何帮助或指示?
您将如何仅使用CSS应用背景颜色,而仅将颜色应用于可见文本.
我想要实现以下目标:
<div style="width:200px;background-color:white;">
<p style="background-color:red;color:black;">This text is longer than 200 pixel and therefore a line break will occur</p>
</div>
Run Code Online (Sandbox Code Playgroud)
不幸的是,背景应用于<p>-tag 的完整,而不是在换行符之前的最后一个字符结束.在旁注中,我无法手动换行显示的文本.
所以如果上面的输出看起来像这样:
----------this line is exactly 200px----------
This text is longer than 200 pixel and
therefore a line break will occur
----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
所以背景颜色应该在第一行以"and"结尾,在第二行以"occurrence"结束,留下<div>白色的背景.
我真的把头发拉出来,如果没有手动设置换行符,甚至可以获得输入?我也会使用javascript解决方案,但更喜欢css只有一个.
我真的把头发拉出来了.我在自建的php应用程序上有一个简单的评论部分,如果我抓住$ _GET参数,我只想添加一个新行.但无论我如何构建MySQL插入请求,我都会收到错误.
这是我到目前为止:
if(isset($_GET['r'])){
$replyid = mysql_real_escape_string($_GET['r']);
$sentnow = date("Y-m-d H:i:s");
mysql_query("INSERT INTO eis_inbox (messageid, toid, from, contact, seen, message, date) VALUES (NULL, '".$replyid."', 'TESTUSER', 'CONTACTINFO', '0', 'MESSAGE', '".$sentnow."'") or die(mysql_error());
echo '<meta http-equiv="refresh" content="0;/messages">';
}
Run Code Online (Sandbox Code Playgroud)
我的MySQL数据库字段被称为完全相同:messageid(auto_increment),toid(int11),from(varchar255),contact(varchar255),seen(int3),message(text)和date(timestamp/CURRENT_TIMESTAMP).
执行上面的页面,让我们说"index.php?r = 777"应该,正如我所看到的,用一个新行填充我的MySQL:
messageid = (AUTO_INCREMENT)
toid = 777
from = TESTUSER
contact = CONTACTINFO
seen = 0
message = MESSAGE
date = 2013-01-17 11:50:01
Run Code Online (Sandbox Code Playgroud)
相反,我收到以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server …Run Code Online (Sandbox Code Playgroud)