2013-08-23 21 views
1

我有一个OpenCart VQMod,它目前按字符计数字符串长度和收费。它完美的作品,但我需要它的规则如下收​​费:基于字符数计算字符串长度和收费价格的PHP函数

30-45个字符:$ 8.50

46+字符:$ 12.00

编辑: 截至目前,这个mod乘以串长度与每个角色的价格有关,但我需要它只收取30-45个字符的单位8.50美元,或46个字符以上的12美元。任何人都可以帮我修改下面的PHP吗?我在这里粘贴整个文件。迄今为止,非常感谢您的回复。我非常感谢社区的帮助。

编辑2:删除不必要的代码,只显示字符串长度的药水。

    //Q: Option Price By Character 
        $optprice = ''; 
        $optprefix = ''; 
        if ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea') { 
          if (strlen($option_value)) { 
           $optprice = (strlen($option_value) * $option_query->row['price_per_char']); 
           $optprefix = '+'; 
           $option_price += $optprice; 
+0

什么是与你的代码的具体问题? – StephenTG

+0

@StephenTG,我需要帮助逻辑,特别是这部分://Q:选项价格按字符 $ optprice =''; $ optprefix =''; if($ option_query-> row ['type'] =='text'|| $ option_query-> row ['type'] =='textarea'){ if(strlen($ option_value)){ $ optprice =(strlen($ option_value)* $ option_query-> row ['price_per_char']); $ optprefix ='+'; $ option_price + = $ optprice; } } – stmikhail

回答

0
if ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea') { 
    if (strlen($option_value)) { 
     // LumberJack's new code 
     $string_length = strlen($option_value); 
     if($string_length >= 30 && $string_length <= 45) 
     { $optprice = 8.5; } 
     else if($string_length >= 46) 
     { $optprice = 12.00; } 
     else { 
     // end my new code 
      $optprice = (strlen($option_value) * $option_query->row['price_per_char']); 
     } // I moved this up two lines 
     $optprefix = '+'; 
     $option_price += $optprice; 
    } 
} 
+0

令人惊叹。这是解决方案 - 感谢您的帮助! – stmikhail

0

首先找出哪一个是最大的数字。在这种情况下,它的45

$price = 8.50; 
for(i=1;i<45;i--){ 

    echo i - $price.'<br/>'; 
    if(i < $price){ 
     break; 
    }  
}