PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 4th, 2005, 09:25 AM
tankpark tankpark is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 tankpark User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 32 sec
Reputation Power: 0
Parse Error

echo "
<html>
<head>
<title>Post Your Reply in $topic_title</title>
</head>
<body>
<h1>Post Your Reply in $topic_title</h1>
<form method=post action=\"$_SERVER['PHP_SELF']\">

<p><strong>Your Email Address:</strong><br /></p>
<input type=\"text\" name=\"post_owner\" size=40 maxlenght=150 />

<p><strong>Post Text:</strong><br />
<textarea name=\"post_text\" rows=8 cols=40 wrap=virtual></textarea></p>

<input type=\"hidden\" name=\"op\" value=\"addpost\" />
<input type=\"hidden\" name=\"topic_id\" value=\"$topic_id\" />

<p><input type= \"submit\" name=\"submit\" value=\"Add Post\" /></p>

</form>
</body>
</html>";

I am getting the following error msg on the highlighted line
"Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in" If someone could advise it would be greatfully appreciated.

Reply With Quote
  #2  
Old March 4th, 2005, 11:36 AM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 331 Viper_SB User rank is Private First Class (20 - 50 Reputation Level)Viper_SB User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 7 sec
Reputation Power: 6
variables used within quoted string you SHOULD put curly braces around them i.e
<form method=post action=\"{$_SERVER['PHP_SELF']}\">

for the most part it's only needed for arrays within a quoted string, but for good coding I'd recommened using them for all variables within a quoted string, here is how your code would look rewritten.

PHP Code:
echo "
<html>
<head>
<title>Post Your Reply in {$topic_title}</title>
</head>
<body>
<h1>Post Your Reply in {$topic_title}</h1>
<form method=post action=\"{$_SERVER['PHP_SELF']}\">

<p><strong>Your Email Address:</strong><br /></p>
<input type=\"text\" name=\"post_owner\" size=40 maxlenght=150 />

<p><strong>Post Text:</strong><br />
<textarea name=\"post_text\" rows=8 cols=40 wrap=virtual></textarea></p>

<input type=\"hidden\" name=\"op\" value=\"addpost\" />
<input type=\"hidden\" name=\"topic_id\" value=\"{$topic_id}\" />

<p><input type= \"submit\" name=\"submit\" value=\"Add Post\" /></p>

</form>
</body>
</html>"



around thing I'd recommend AGAINST using echo for printing out large portions of html like this, instead use heredoc this way you can avoid using all the backslashes

PHP Code:
 $string <<<EOS
<html>
<head>
<title>Post Your Reply in 
{$topic_title}</title>
</head>
<body>
<h1>Post Your Reply in 
{$topic_title}</h1>
<form method=post action="
{$_SERVER['PHP_SELF']}">

<p><strong>Your Email Address:</strong><br /></p>
<input type="text" name="post_owner" size=40 maxlenght=150 />

<p><strong>Post Text:</strong><br />
<textarea name="post_text" rows=8 cols=40 wrap=virtual></textarea></p>

<input type="hidden" name="op" value="addpost" />
<input type="hidden" name="topic_id" value="
{$topic_id}" />

<p><input type= "submit" name="submit" value="Add Post" /></p>

</form>
</body>
</html>
EOT; // NOTE this MUST be at the beginning of the line, otherwise you'll get a parse error 

Reply With Quote
  #3  
Old March 4th, 2005, 12:03 PM
tankpark tankpark is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 tankpark User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 32 sec
Reputation Power: 0
cheers Viper you are a lifesaver

Reply With Quote
  #4  
Old March 4th, 2005, 12:08 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey Viper_SB! I was just looking at your post and I have to say, it's one hell of an explanation. I wanted to congratulate you for that. Many people wouldn't go through the trouble of rewriting the code, specialy with colors (how Kindergarten of you!! )

Anyway...congratulations and good luck to all of you!

Anibal.

Reply With Quote
  #5  
Old March 5th, 2005, 05:19 PM
atatum atatum is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 3 atatum User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 49 sec
Reputation Power: 0
Quote:
Originally Posted by Viper_SB
variables used within quoted string you SHOULD put curly braces around them i.e
<form method=post action=\"{$_SERVER['PHP_SELF']}\">

for the most part it's only needed for arrays within a quoted string, but for good coding I'd recommened using them for all variables within a quoted string, here is how your code would look rewritten.

This was a great post. Would you mind just explaining the reason for the curly braces? I'm a fairly new programmer and I've not done this before. I'm just wondering if I should fix all my old code.



Thanks.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Parse Error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT