Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

printing mailing label without blank line

firestar_lenefirestar_lene Posts: 33Member
i have a problem.i want to print mailing label using pdf.


[php]

$pdf->Add_PDF_Label(sprintf("%s
%s
%s
%s
%s %s
%s %s", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));
[/php]

if one the data is empty,i dont want to leave a blank like,like as below:


name
address1

address3


assume there is no data for address2,it will leave a blank space there.i dont want this to happen.i want to put something like this as below:

[php]

$pdf->Add_PDF_Label(sprintf("%s if(!empty($address1))
%s if(!empty($address2)){
%s}if(!empty($address3)){
%s}if(!empty($postcode) or !empty($city)){
%s %s}if(!empty($state) or !empty($country)){
%s %s}", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));
[/php]


but it display error when i put the condition(if statement) inside the sprintf..how to put the condition inside?


Comments

  • netgertnetgert Posts: 331Member
    : i have a problem.i want to print mailing label using pdf.
    :
    :
    : [php]
    :
    : $pdf->Add_PDF_Label(sprintf("%s
    %s
    %s
    %s
    %s %s
    %s %s", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));
    : [/php]
    :
    : if one the data is empty,i dont want to leave a blank like,like as below:
    :
    :
    : name
    : address1
    :
    : address3
    :
    :
    : assume there is no data for address2,it will leave a blank space there.i dont want this to happen.i want to put something like this as below:
    :
    : [php]
    :
    : $pdf->Add_PDF_Label(sprintf("%s if(!empty($address1))
    %s if(!empty($address2)){
    %s}if(!empty($address3)){
    %s}if(!empty($postcode) or !empty($city)){
    %s %s}if(!empty($state) or !empty($country)){
    %s %s}", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));
    : [/php]
    :
    :
    : but it display error when i put the condition(if statement) inside the sprintf..how to put the condition inside?
    :
    :
    :
    a clean solution would be to store all the values in an array and then loop through them and build the format string on-the-fly. the above script is incorrect because you cant use functions in strings, you have to end the string and then call the function, like [ITALIC]$asdf = "foo".strtoupper("bar")."!";[/ITALIC]. also note if you conditionally build the param string, you also have to conditionally pass parameters as otherwise the indexes get mixed up and the result is not what you expected (you still get blanks as you pass blank params, but you will not use all the params as the number of %s is smaller than number of params passed, so some data will be discarded and other will be shifted - not what you want probably)
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Sign In or Register to comment.