Welcome to WebmasterWorld Guest from 54.226.45.241

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse error: syntax error

     

oldcode

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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

rocknbil

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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. :-)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month