if(length($brand_string) gt 0){ $materialmapping_item2->setAttribute('brand',$brand_string); } if(length($ignored_brand_string) gt 0){ $materialmapping_item2->setAttribute('ignore_brand',$ignored_brand_string); }