Page 1 of 2

Parse error in HTMLEOF

Posted: Mon Oct 18, 2004 11:23 pm
by C_Calav
hi guys ive just put some code in between

(snippet taken from whole code)

function print_form()
{
print <<<HTMLEOF

Code: Select all

<?php
function GetCartId() 
{ 
if(isset($_COOKIE["cartId"])) 
{ 
return $_COOKIE["cartId"]; 
} 
else 
{ 
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30)); 
return session_id(); 
} 
} 
?>
HTMLEOF;
}

and am getting

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/users/modelair/modelaircraft.co.nz/htdocs/summary.php on line 156

156 = if(isset($_COOKIE["cartId"]))

the code before worked perfectly before i put it in this function. are there rules or stuff like that to think about when doing this?

and could someone help me with the above problem and how i can avoid this in future? bound to run into more in this function.

Posted: Mon Oct 18, 2004 11:38 pm
by feyd
print_form looks like a php function. In which case, having <?php inside a print will attempt to print the code. Try putting {} around the variables.

you need to practice more on your posting of code. :P

Posted: Mon Oct 18, 2004 11:46 pm
by C_Calav
i left that bit out of the code on purpose! to show that the middle bit was a snippet of the code! i thought it would of helped!

ok, so.. in the php function where ever i have have php tags i just put {} around them?

can you please show me feyd in the code i posted? or an example?

thanx!

Posted: Mon Oct 18, 2004 11:53 pm
by feyd
if and where you put the braces depends on what you are trying to do. The code you posted would try to print out php code. What this your intention??

Posted: Tue Oct 19, 2004 2:50 am
by C_Calav
my intention is to print a summary page i have inside of the htmleof


below is a SAMPLE purchase form...

i have to put my summary page into this code. but mine is alot more complex and im not sure how to go about doing it.

any help would be great! thanx feyd. (or anyone else for that matter)

is that more clear?

Code: Select all

<?php
#******************************************************************************
# This function prints a blank purchase form.
#******************************************************************************
function print_form()
{
  print <<<HTMLEOF
<html>
<head>
<title>Direct Payment Solutions: Secure Payments Page PHP Sample</title>
</head>
<body>
<h1>Direct Payment Solutions: Secure Payments Page PHP Sample</h1>
<p>
You have indicated you would like to buy some widgets.
</p>
<p>
Please enter the number of widgets below, and enter your
shipping details.
</p>
<form method="post">
<table>
  <tr>
    <td>Quantity:</td>
    <td><input name="Quantity" type="text"/></td>
    <td>@ \$1.20 ea</td>
  </tr>
  <tr>
    <td>Ship to</td>
    <td></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><input name="Address1" type="text"/></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input name="Address2" type="text"/></td>
  </tr>
</table>
<input name="Submit" type="submit" value="Submit"/>
&nbsp;Click submit to go to the secure payment page.
</form>
</body>
</html>
HTMLEOF;
}

#*****************************************************************************
?>

Posted: Tue Oct 19, 2004 2:55 am
by feyd
ok.. since you want to run code inside the function, lose the heredoc junk (print <<<HTMLEOF).. just code like normal. Have it echo out whatever it needs to, 'cause that's what your heredoc code example does.

Posted: Tue Oct 19, 2004 3:07 am
by C_Calav
ok thanx feyd, this is not my code, its a payment company type place.. so i just loose the print <<<HTMLEOF) and code like normal ok i think i can handle that!

cheers feyd!

Posted: Tue Oct 19, 2004 3:11 am
by C_Calav
feyd.. one more question.. does that mean i take out all my php tags where i have code in that function?

edit: and how do i echo my html i tried a few times can you give me a example thanx :)

edit: how would i print or echo this for example? thanx

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Model Aircraft</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all">
		@import url(Payment%20Express/model.css);
	</style>


		<script type="text/javascript">
		<!--
		function getWindowHeight() &#123;

Posted: Tue Oct 19, 2004 9:06 am
by feyd
C_Calav wrote:feyd.. one more question.. does that mean i take out all my php tags where i have code in that function?

edit: and how do i echo my html i tried a few times can you give me a example thanx :)

edit: how would i print or echo this for example? thanx

Code: Select all

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Model Aircraft&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;style type="text/css" media="all"&gt;
		@import url(Payment%20Express/model.css);
	&lt;/style&gt;


		&lt;script type="text/javascript"&gt;
		&lt;!--
		function getWindowHeight() &#123;
dumping text to the browser is often done through the heredoc... but you don't put actual code inside the heredoc block. it's supposed to be around the heredoc, otherwise it won't be processed like normal code. so:

Code: Select all

// php code here

echo <<<STOP
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Model Aircraft</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all">
		@import url(Payment%20Express/model.css);
	</style>


		<script type="text/javascript">
		<!--
		function getWindowHeight() {
STOP;

// php code out here too

Posted: Tue Oct 19, 2004 2:48 pm
by C_Calav
thanx feyd for all your help! that should solve it will oook at it after work. one more small thing though.. what happens if i have some php in the heredoc? u know posting variables etc?

thanx

Posted: Tue Oct 19, 2004 2:50 pm
by feyd
it's just like being in a string, so you can have variables (that will get parsed into their values), but not code.

Posted: Wed Oct 20, 2004 10:49 pm
by C_Calav
hey feyd, i got the start bit ok but how can i stop it?
STOP;
this does not seem to be working?

here is my start and end code. thanx

Code: Select all

<?php
echo <<<STOP
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
?>

Code: Select all

<?php
</div>
<!-- End Footer -->
</body>
</html>
STOP;
}

#***********************************************
?>

Posted: Wed Oct 20, 2004 11:03 pm
by feyd
post more code please.. as those put together (removing the last brace) works just fine. although it may output a bit different than you think.. (the php start and end tags print out. :))

Posted: Wed Oct 20, 2004 11:10 pm
by C_Calav
ok, this is what it more looks like, with out the php tags.

on the second bit of code at the bottom after the

STOP;
}

bit, all the code is black (not colourcoded) and is printed to the page in the 'show design view' of dreamweaver.

so it looks like the stop tag is not doing its job. is this more helpfull or do you need the whole code or ?

thanx

Code: Select all

echo <<<STOP
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Model Aircraft</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

Code: Select all

<!-- Begin Footer -->
<div id="footer"> 
	<h3>copyright &copy; 2004 Model Aircraft</h3>
</div>
<!-- End Footer -->

</body>

</html>

STOP;
&#125;


#************************************************************
# This function formats data into a request and redirects to the 
# Payments Page.
#************************************************************
function redirect_form()
&#123;
  global $pxaccess;
  
  $request = new PxPayRequest();

Posted: Wed Oct 20, 2004 11:30 pm
by feyd
so you have php code between these 2 code blocks? If so, and you want them to actually get run, you need to stop and restart the heredoc.