我希望这个代码在实际计数和年份之间有几个0 's


I want this code to have a couple of zero's between the actual counting and the year

有人能告诉我如何才能使以下脚本输出:2015000001和201500002。现在给出了20151、20152等等。这个脚本在联系表单7上统计我的表单提交,所以每封邮件得到一个唯一的递增数,但我希望计数从4或之后开始5 0。所以201500001

//Define the key to store in the database
define( 'CF7_COUNTER', 'cf7-counter' );
//Create the shortcode which will set the value for the DTX field
function cf7dtx_counter(){
$val = date( 'Y' ) . get_option( CF7_COUNTER, 0) + 1; //Increment the current count
return $val;
}
add_shortcode('CF7_counter', 'cf7dtx_counter');
//Action performed when the mail is actually sent by CF7
function cf7dtx_increment_mail_counter(){
$val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count
update_option(CF7_COUNTER, $val); //Update the settings with the new count
}
add_action('wpcf7_mail_sent', 'cf7dtx_increment_mail_counter');

感谢到目前为止的帮助。顺便说一句,有人知道我怎么重置吗返回0,重新开始计数。

我从这篇文章中得到了它,所以你可以检查:http://sevenspark.com/tutorials/how-to-create-a-counter-for-contact-form-7

问候,银行

function cf7dtx_counter(){
    $year = date('Y');
    $counter = get_option( CF7_COUNTER, 0) + 1;
    $val = sprintf('%d%05d', $year, $counter);
    return $val;
}

第二个值($counter)将用0字符填充,总长度为5个字符,这就是%05d所做的。

Sımply改变这一行

$val = date('Y')。get_option(CF7_COUNTER, 0) + 1;//增加当前计数

;

$val = date('Y')*100000 + (get_option(CF7_COUNTER, 0) + 1);//增加当前计数

要更新计数器变量,必须调用这个函数

update_option (CF7_COUNTER 0);//使用新的count

更新设置