Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing without leaving blank line

Status
Not open for further replies.

lenelene

Programmer
Joined
Dec 10, 2002
Messages
57
Location
MY
i have a problem.i want to print mailing label using pdf.


PHP:
$pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s\n%s %s\n%s %s", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));

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))\n%s if(!empty($address2)){\n%s}if(!empty($address3)){\n%s}if(!empty($postcode) or !empty($city)){\n%s %s}if(!empty($state) or !empty($country)){\n%s %s}", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));


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

 
You don't put the condition inside.

Use the if-statement outside the method invocation to build your string. Then pass the string to the method.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top