如果字符串为空,请让php sprintf省略return

I am wresting with printing shipping labels and getting the final output to omit a second address line if one exists. Is there a way to conditionally exclude the line break if $address2 is empty when using sprintf()?

            while($rows=mysql_fetch_array($result)){
                $name = $rows['address_name'];
                $address = $rows['street1'];
                $address2 = $rows['street2'];
                $citystatezip = $rows['city'].', '.$rows['state'].' '.$rows['zip'];
                $country = $rows['country'];
                $text = sprintf("%s
%s
%s
%s
", $name, $address, $address2, $citystatezip, $country);
                $pdf->Add_Label($text);
            }

Your sprintf only has 4 '%s' and 5 params.

In this code, I removed the from the sprintf into a conditional above.

        // Don't use mysql_xxxx functions
        // Should really be using PDO       
        //          +---------------+
        //          |               |
        while($rows=mysql_fetch_array($result)){
            $name = $rows['address_name'];
            $address = $rows['street1'];
            $address2 = $rows['street2'];
            $citystatezip = $rows['city'].', '.$rows['state'].' '.$rows['zip'];
            $country = $rows['country'];
            $addr2 = empty($address2) ? '' : $address2 . "
";
            $text = sprintf("%s
%s
%s%s
%s
", $name, $address, $addr2, $citystatezip, $country);
            $pdf->Add_Label($text);
        }