我发现自己需要这个功能,并且想知道它是否已经存在于PHP中.
/**
* Truncates $str and returns it with $ending on the end, if $str is longer
* than $limit characters
*
* @param string $str
* @param int $length
* @param string $ending
* @return string
*/
function truncate_string($str, $length, $ending = "...")
{
if (strlen($str) <= $length)
{
return $str;
}
return substr($str, 0, $length - strlen($ending)).$ending;
}
Run Code Online (Sandbox Code Playgroud)
因此,如果限制是40并且字符串是"快速狐狸跳过懒惰的棕色狗",输出将是"快速狐狸跳过懒惰的眉毛......".这似乎是PHP中存在的那种东西,所以当我找不到它时我感到很惊讶.
我们最近在我们的服务器上启用了APC,偶尔当我们发布新代码或更改时,我们发现更改的源文件开始抛出未反映在代码中的错误,通常会解析描述不符合的令牌的错误存在.我们通过运行php -l错误日志所说的受影响的文件来验证这一点.通常,重新发布可以解决问题.我们使用的是PHP 5.2.0和APC 3.01.9.我的问题是,有其他人遇到过这个问题,还是有人认出我们的问题是什么?如果是这样,你是如何解决它或我们如何解决它?
编辑:我应该添加一些关于我们的发布过程的细节.正在通过rsync从登台服务器将内容推送到生产服务器.我们启用了apc.stat_ctime因为它说这有助于使用rsync更顺畅. apc.write_lock默认情况下处于启用状态,我们尚未禁用它.同上apc.file_update_protection.
我正在运行一个脚本,该脚本对文件的内容进行一些更改,然后将其修改时间重置为以前的时间。间歇地,我会在日志中发现以下错误:
Run Code Online (Sandbox Code Playgroud)touch() [function.touch]: Utime failed: Operation not permitted
file_put_contents()通话刚结束时,这似乎已更改了我尝试处理的文件的内容touch()。没有与该file_put_contents()行相关的错误。
有人发生过这种情况吗?谁能找出允许我写文件但不更改其修改时间的权限集?我正在Linux上执行此操作。
我有一个无序的项目列表,这样的东西,为简洁而缩短:
<div id="elementsContainer">
<ul>
<li><a>One</a></li>
<li><a>Two</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我将列表设置为样式,但这3种样式处理列表项的背景图像:
#elementsContainer ul li {
list-style:none;
}
#elementsContainer a {
background: transparent url(/images/icons/bullet_delete.png) no-repeat 5px 50%;
}
#elementsContainer a:hover,
#elementsContainer a:focus,
#elementsContainer a:active {
background:#fff url(/images/icons/delete.png) no-repeat 5px 50%;
}
Run Code Online (Sandbox Code Playgroud)
该列表看起来很棒 - 它为每个列表项的文本左侧添加了一个小删除图标.但是,我希望使用jQuery(1.3)来处理每个项目的点击事件,我希望列表项的背景图像和列表项的文本之间具有单独的功能.如果我单击图像,我想删除该项目.如果我单击文本,我想编辑该项目.
我开始使用这样的东西:
$("a").live("click", function(event){
alert( $(this).text() );
});
Run Code Online (Sandbox Code Playgroud)
但我没有看到$(this)或"event"中的任何内容,我可以确定是否单击文本或图像.
是的,我知道我可以只有一个单独的"img"标签并单独处理它的点击.如果这是唯一的选择,我会走那条路.我只是想知道是否有某种方法可以使它在背景图像上工作.
提前致谢!
我正在与Doctrine一起开展我的第一个Symfony项目,而且我遇到了麻烦.我正试图用两名球员表达一场比赛.我想要的关系是PlayerOne和PlayerTwo,每个都被键入Users表中的ID.这是我到目前为止的一部分:
Game:
actAs: { Timestampable:- }
columns:
id: { type: integer, notnull: true, unique: true }
startDate: { type: timestamp, notnull: true }
playerOne: { type: integer, notnull: true }
playerTwo: { type: integer, notnull: true }
winner: { type: integer, notnull:true, default:0 }
relations:
User: { onUpdate: cascade, local: playerOne, foreign: id}
User: { onUpdate: cascade, local: playerTwo, foreign: id}
Run Code Online (Sandbox Code Playgroud)
这不起作用.它构建良好,但它生成的SQL只包含playerTwo的约束.我尝试过其他一些东西:
User: { onUpdate: cascade, local: [playerOne, playerTwo], foreign: id}
Run Code Online (Sandbox Code Playgroud)
也:
User: [{ onUpdate: cascade, local: playerOne, foreign: id}, …Run Code Online (Sandbox Code Playgroud) php ×3
apc ×1
doctrine ×1
filesystems ×1
html-lists ×1
javascript ×1
jquery ×1
list ×1
mysql ×1
string ×1
symfony1 ×1
yaml ×1