开发者

PHP "if empty" help Joomla - VirtueMart

I'm having trouble with this code. I开发者_开发百科f the field customer_note is empty, need it to return a value of N and Y if there is text in the field. The resulting Y or N is being passed into an XML line. I'm using PHP 5.2.9.

Thank you.

if( !empty( $customer_note )) {
  $shopper_message .= $customer_note."\n";
} else {
  $shopper_message .= "\n";
}


I'm not sure if you want this:

< ?php 
function check_ifempty($customer_note)
    {
        if (empty($customer_note)) 
        { 
  return "N"; 
 } 
 else 
 { 
  return "Y"; 
 } 
} 
?>

< ?php 
$customer_note = $_POST["customer_note"]; 
$result = check_ifempty($customer_note); 
$xml .= $result; 
?> 


$has_customer_note = empty($customer_note) ? 'N' : 'Y';

Check out the part about return values of empty to see what is considered an empty value.

An alternative can be to use strlen.

$has_customer_note = strlen($customer_note) > 0 ? 'Y' : 'N';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜