[SOLVED] unexpected $ with fpdf

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

[SOLVED] unexpected $ with fpdf

Post by pad4ever »

Hi there guys, i got the following problem. Maybe you can help me:

I'd like to write a PDF with some HTML & PHP code. So i figured i'd use fpdf. Here is a a little example of the code:

----------------------------------------------------

Code: Select all

<?

$html="";
		$html=<<<PDF_BODY
		<table border="0" cellspacing="0" cellpadding="0" width="600">
		<tr>
			<td>
				<table border="0" cellspacing="0" cellpadding="10" width="100%">
				<tr>
					<td width="100%" valign="top"> 
						<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td class="title"><font class="title">{$productlang['name']}</font><td>
						</tr>
						<tr>
							<td height="10"></td>
						</tr>
						<tr>
							<td>{$description}</td>
						</tr>
		PDF_BODY;
						if ($properties&&{$product['has_properties']}){
		$html.=<<<PDF_BODY
						<tr>
							<td>
								<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<tr>
									<td nowrap><font>{$_TEXT['techdata']}:</font></td>
								</tr>
								<tr>
									<td>
										<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
										<tr>
											<td><img src="_images/spacer.gif" border="0" width="1" height="5"></td>
										</tr>
		PDF_BODY;


// create pdf
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->SetMargins(20,20,20,20);
		$pdf->SetFont('Arial','', 10);
		$pdf->SetTextColor(0,0,0);
		$pdf->SetXY(20,50);
		$pdf->Ln(35);
		$pdf->WriteHtml($html);
		$pdf->Ln(25);

$pdf->Output();

?>
The actual script is bigger but it's too long to post it here. Anyway. Everytimer i try to run the script i get this msg:

Parse error: parse error, unexpected $ in /web/www/eyemedia_ch/clients/public_html/candyhoover.ch/modules/mo_products_print.php on line 177

with line 177 being the last line of the script.

Now i know that this error usually describes a missing { or } or whatever but i double and triple checked the code. Did anyone expirience this problem before?

Thanks in advance for any help
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

your code looks incorrect

you have this line

Code: Select all

if ($properties&&{$product['has_properties']}){
but you have no closing } anywhere that i can see!
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

Post by pad4ever »

i know. it has a closing tag. The reason why i didn't post the whole code is because it's way too long. the closing tag is there. all tags which are opened are closed. i thought there maybe something wrong with the whole $pdf thing...
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

pad4ever wrote:i know. it has a closing tag. The reason why i didn't post the whole code is because it's way too long. the closing tag is there. all tags which are opened are closed. i thought there maybe something wrong with the whole $pdf thing...
Just post the whole code....we cant look for mistakes if we cant see it all
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

Post by pad4ever »

Code: Select all

<?
		require_once('application.php');
		
		global $_APP, $_TEXT;	
		/* Create database pointer */
		$db = &$_APP['masterdb'];
		$db->connect();
		
		/* Template Defaults */
		setGET('productid', -1);	
		
		/* Create objects */
		if (!isset($kshop))
			$shop = new kshop($db);
		
		/* Get Service folders */
	if ($module == 'products')
		$product = $shop->get_product($_GET['productid']);
	else
		$product = $shop->get_product($_GET['productid'], 2);
		$productlang = &$product['languages']['DE'];
		
		// set vars
		$description = str_replace("/accounts/", $_APP['baseurl']."/accounts/", $productlang['description']);
		
		// get properties
		$properties = $shop->get_properties($product['folderid']);
		// outcluded properties
		$properties_out = array(150); // comma seperated propertyid's
		
		// product_details
		$details = $shop->get_product_details($_GET['productid']);
		$has_images = $details && isset($details['PRODUCT_IMAGES']) ? true : false;
		$brand = current(explode(".",$_GET['action']));
		
		$test = 1;
		$html="";
		$html = <<<PDF_BODY
			<table>
			<tr>
				<td width="450"><br></td>
			</tr>
			<tr>
				<td width="200" align="right"><strong>tests2</strong></td>
			</tr>	
			<tr>
				<td>test1</td>
			</tr>
			<tr>
				<td width="450"><br></td>
			</tr>
PDF_BODY;
		if($test==1)
		{
			$html.= <<<PDF_BODY
			<tr>
				<td>TEST</td>
			</tr>
		</table>
		}
		else
		{
			<tr>
				<td>FNORD</td>
			</tr>
		}
PDF_BODY;
		// create pdf
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->SetMargins(20, 20, 20, 20);
		$pdf->SetFont('Arial', '', 10);	
		$pdf->SetTextColor(0, 0, 0);
	
		$pdf->SetXY(20, 50);
	
		$pdf->Ln(35);
		$pdf->WriteHtml($html);
		
		$pdf->Ln(25);
		$pdf->Output($_APP['basepath']."/pdf/pdf.pdf", 'F');
?>
well ok. here's the important part. i deleted everything else in my script but it still doesn't work.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

only thing obvious i can see at a quick glance that you closing HEREDOC tags have to be on their own line with nothing else on that line (including whitespace).

Make sure there is nothing else on the line that have "PDF_BODY; " on them
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

Post by pad4ever »

uhmmm... i just found the mistake. forgot the "<<<PDF_BODY" part sometimes. s'all good now;) thanks anyway;)

close thread
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

if($test==1)
        {
            $html.= <<<PDF_BODY
            <tr>
                <td>TEST</td>
            </tr>
        </table>
        }
        else
        {
            <tr>
                <td>FNORD</td>
            </tr>
        }
PDF_BODY;
Should be

Code: Select all

if($test==1)
        {
            $html.= <<<PDF_BODY
            <tr>
                <td>TEST</td>
            </tr>
        </table>
PDF_BODY;

        }
        else
        {
            $html.= <<<PDF_BODY
            <tr>
                <td>FNORD</td>
            </tr>
PDF_BODY;

        }
You can't close off conditionals or even add else statements inside your heredoc ;) It's all just read as part of the string so your heredoc wasn't terminated ;)

EDIT | Well done!
Post Reply