我刚刚注意到PHP日期函数很奇怪,有人可以解释一下我做错了什么吗?
以下代码显示相同的结果
<?php
echo date('Y-m-t');
// Outputs last day of this month: 2016-03-31
echo date('Y-m-t', strtotime("-1 month"));
// For some reason outputs the same: 2016-03-31
echo date('Y-m-t', strtotime("+1 month"));
// Outputs 2016-05-31
Run Code Online (Sandbox Code Playgroud)
这可能只是我愚蠢,但有人可以解释我为什么会这样吗?
我有很大的时间尝试将字符串转换为整数或乘以两个整数.我无法将字符串转换为整数,因为它导致我成为一个布尔值(当我使用var_dump时).我可以转换字符串中的其他整数,但我无法将其相乘.
我有这个:
<? $fees=$commerce->cart->get_total();
$payfee = str_replace(' €', '', $fees);
$payfee = str_replace(',','', $payfee); //this is the string
$fee = 0.025;
$paypal = $payfee * $fee; //this thing is not working
?>
Run Code Online (Sandbox Code Playgroud)
我尝试将payfee转换为整数,但仍然无法使其工作.之前我做过类似的事情并且运作良好,但这次不是.
任何帮助将不胜感激.
PS感谢整个stackoverflow.com社区,它曾多次帮助过我.
我在数据库中有一些项目如下
Item Description
--------------------------
Item 1 Some text here
Item 2 Some text
Item 3 Some text here
Item 4 Some
Item 5 Some text here
Run Code Online (Sandbox Code Playgroud)
这里的客户要求是如果描述超过15个字符,那么我们应该只显示15个字符并且应该显示一些虚线(...).如果描述少于15个字符,那么我们将显示全文(现在虚线不应该在那里)
为此我写了下面的代码.
<?php
if(strlen($row['description'])>15) {
echo mb_substr($row['description'],0,15,"UTF-8");
echo" . . . . .";
}
else
{
echo $row['description'];
}
?>
Run Code Online (Sandbox Code Playgroud)
在英语的情况下,代码工作正常,但在日语的情况下,它会产生问题.意味着即使文本少于15个字符虚线也会显示(仅在少数情况下)
可能是什么问题?
我在一组25,000个结果中运行下面的代码.我需要优化它,因为我达到了内存限制.
$oldproducts = Oldproduct::model()->findAll(); /*(here i have 25,000 results)*/
foreach($oldproducts as $oldproduct) :
$criteria = new CDbCriteria;
$criteria->compare('`someid`', $oldproduct->someid);
$finds = Newproduct::model()->findAll($criteria);
if (empty($finds)) {
$new = new Newproduct;
$new->someid = $oldproduct->someid;
$new->save();
} else {
foreach($finds as $find) :
if ($find->price != $oldproduct->price) {
$find->attributes=array('price' => $oldproduct->price);
$find->save();
}
endforeach;
}
endforeach;
Run Code Online (Sandbox Code Playgroud)
代码通过someid比较两个表的行.如果发现巧合则更新价格列,如果没有创建新记录.
编辑:这令人尴尬...我忘了连接到数据库.抱歉给你带来不便 :(
我想回显变量$ number_row的值,但没有显示任何内容
<?php
$resultado = mysql_query("SELECT * FROM videos"); // this counts how many videos are
$number_rows = mysql_num_rows($resultado);
echo "$number_rows";
?>
Run Code Online (Sandbox Code Playgroud) 我一直遇到这个问题一段时间了:
v = jQuery("span.count").html().replace(/\(|\)/g, "");
jQuery("span.count").html(v);
Run Code Online (Sandbox Code Playgroud)
我在SO上找到了这个对于括号很有用的但是我似乎无法使用垂直条|.
php ×5
date ×1
foreach ×1
function ×1
int ×1
javascript ×1
memory ×1
mysql ×1
optimization ×1
regex ×1
string ×1
strlen ×1
woocommerce ×1
yii ×1