以正确的顺序回显变量

时间:2018-10-10 10:36:47

标签: php wordpress

设置

我决定自己尝试一点PHP,我是一个完全的初学者。

我经营一家WooCommerce商店,并希望在每个产品页面上动态显示预期的交货日期范围。

交货日期范围是今天的日期加上3天和4天,例如今天是10月10日,因此交货日期范围是10月13日至14日。因此,在每个产品页面上都应提及

Delivery between Oct 13 and Oct 14

我知道在哪里编写代码,以便它显示我希望其在产品页面上显示的位置。

我还知道如何动态更新交货日期。


问题

Echo混合变量,而不是

Delivery between Oct 13 and Oct 14

它声明,

Delivery between and Oct 13Oct 14


我的代码

function my_custom_action() { 

    $plus3 = strtotime("+3 day");
    $plus4 = strtotime("+4 day");   
    $date_low = date('M d', $plus3);
    $date_high = date('M d', $plus4);
    $start_text = _e('Delivery between ','woodmart');
    $end_text = _e(' and ','woodmart');

    echo $start_text, $date_low, $end_text, $date_high ;
};     
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 ); 

我在函数中需要$start_text$end_text,以便字符串可以翻译。

最好我还可以翻译月份(例如Oct),但是到目前为止,我很高兴知道如何以所需的顺序回显所有变量。

1 个答案:

答案 0 :(得分:-3)

这可以使用字符串插值解决。

例如。

$name = "PHP"; echo "I am reading {$name}POT"; // output: I am reading PHPPOT

这是指向更详细参考文献的链接:variable-interpolation-in-php

相关问题