homepage Welcome to WebmasterWorld Guest from 23.22.128.96
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Parse error: syntax error
oldcode




msg:4473688
 8:19 pm on Jul 8, 2012 (gmt 0)

Hello All. Below is a bit of code which throws an error on line 13. Any thoughts on what's happening?
Parse error: syntax error, unexpected T_SL in C:\xampp\htdocs\borderMaker.php on line 13

<html>
<head>
<title>Your Output</title>
</head>
<body>
<h1>Your Output</h1>
<center>
<?
extract($_REQUEST);
error_reporting(E_ALL & ~E_NOTICE);


$theStyle = <<<HERE
"border-width:$borderSize$sizeType;
border-style:$borderStyle;
border-color:green"
HERE;

print "<div style = $theStyle>";
print $basicText;
print "</div>";

?>
</center>

</body>
</html>

-----------------------------------------------
Here's the html page which calls the php above.
------------------------------------------------
<html>
<head>
<title>Border Maker</title>
</head>
<body>
<center>
<h1>Border Maker</h1>
<h3>Demonstrates how to read HTML form elements</h3>

<form method = "post"
action = "borderMaker.php">


<h3>Text to modify</h3>
<textarea name = "basicText"
rows = "10"
cols = "40">
Four score and seven years ago our fathers brought forth on this
continent a new nation, conceived in liberty and dedicated to the
proposition that all men are created equal. Now we are engaged in a
great civil war, testing whether that nation or any nation so
conceived and so dedicated can long endure.
</textarea>

<table border = 2>
<tr>
<td><h3>Border style</h3></td>
<td colspan = 2><h3>Border Size</h3></td>
</tr>

<tr>
<td>
<select name = borderStyle>
<option value = "ridge">ridge</option>
<option value = "groove">groove</option>
<option value = "double">double</option>
<option value = "inset">inset</option>
<option value = "outset">outset</option>
</select>
</td>
<td>


<select size = 5
name = borderSize>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "5">5</option>
<option value = "10">10</option>
</select>
</td>

<td>
<input type = "radio"
name = "sizeType"
value = "px">pixels<br>
<input type = "radio"
name = "sizeType"
value = "pt">points<br>
<input type = "radio"
name = "sizeType"
value = "cm">centimeters<br>
<input type = "radio"
name = "sizeType"
value = "in">inches<br>
</td>
</tr>
</table>

<input type = "submit"
value = "show me">


</form>

</center>
</body>
</html>

 

g1smd




msg:4473690
 8:52 pm on Jul 8, 2012 (gmt 0)

A Google search revealed a post that linked to this huge warning: [php.net...]
(scroll down a little bit).

Is that of any use?

oldcode




msg:4473698
 10:44 pm on Jul 8, 2012 (gmt 0)

Its not at all clear to me what's wrong and why it doesn't work.

rocknbil




msg:4473847
 4:14 pm on Jul 9, 2012 (gmt 0)

The translation is: it's probably something in your line endings hosing it up in the HEREDOC method. I'd guess that it's what you're editing it in, try Notepad (a NON rich text editor) and upload in ASCII. Your code runs fine as is from here.

If you're going to delve into this subject matter, I'd also suggest a valid doctype and drop the deprecated <center> tags. Apply margin: auto to your form instead, and remove spaces around attribute assignments. (Doesn't relate to PHP, relates to html output.)

oldcode




msg:4473859
 5:20 pm on Jul 9, 2012 (gmt 0)

Thank you both for your responses! I was able to find the problem by removing everything inside the HEREDOC and adding code back in one piece at a time. There was a missing semicolon between $borderSize and $sizeType:
"border-width:$borderSize;$sizeType;border-style:$borderStyle;border-color:green"

g1smd




msg:4473902
 8:32 pm on Jul 9, 2012 (gmt 0)

Yeah, it's usually something so simple you kick yourself when you find it.

rocknbil




msg:4474199
 3:59 pm on Jul 10, 2012 (gmt 0)

As said, it ran verbatim for me. :-) It should have worded fine and is likely to break in your actual CSS now. The reason it works now is probably not what you think, it's likely in editing it you "fixed" the line returns.

As you had it,

border-width:$borderSize$sizeType;

would give

border-width:1px;

and now it will be

border-width:1;px;

.. which is invalid CSS - however since you don't have a valid doctype the HTML output is in Quirks mode and may work by error. :-)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved