PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
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:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 24th, 2008, 09:08 AM
sheel331 sheel331 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 sheel331 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 18 sec
Reputation Power: 0
Parse errors - Unexpected T_CONSTANT_ENCAPSED_STRING

Hello,

I am extremely new to coding in PHP and would appreciate if I could get some assistance on an error I'm receiving in one of my template files. I am getting this error:

PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in header_sgs.html

on this code:

<?php
include '\template\navbar.html';

$fullPath = explode('/', $_SERVER['PHP_SELF']);
echo "The foldername $fullPath[0]";
echo "The filename $fullPath[1]";
if (file_exists('\template\'.$fullPath[1].'.html')) {
include 'c:\inetpub\webroot\soa\template\'.$fullPath[1].'.html';
} else if (file_exists('\template\'.$fullPath[2].'.html')) {
include 'c:\inetpub\webroot\soa\template\'.$fullPath[2].'.html';
}else{
echo "<ul id=\"secondaryNav\" ></ul>";
}

?>

<div id="page">
<!-- BEGIN PAGE CONTENT -->
<?php

if (file_exists("\Images\".$fullPath[1].".gif")) {
echo "<img src="\Images\".$fullPath[1].".gif\" alt=\"".$fullPath[1]."\" />";
}else if (file_exists('\Images\'.$fullPath[1].'.jpg')) {
echo "<img src="\Images\".$fullPath[1].".jpg\" alt=\"".$fullPath[1]."\" />";
}

?>

It says it's failing on the first "if(file_exists...)" piece, but unfortunately, I'm too new to this to understand why it's failing. Help would be greatly appreciated!

Cheers,
Sheel Shah

Reply With Quote
  #2  
Old March 24th, 2008, 10:11 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 530 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 4 m 40 sec
Reputation Power: 3
syntax

Hi sheel331, welcome to the forums
It's easy to get lost when escaping and concatenating.
PHP considers text that's not in quotes to be PHP code, Variables start with $, constants don't.
Take a close look at
PHP Code:
echo "<img src="Images".$fullPath[1].".gif" alt=\"".$fullPath[1]."\" />";
}else if (
file_exists('\Images\'.$fullPath[1].'.jpg')) {
echo "<img src="\Images\".$fullPath[1].".jpg\" alt=\"".$fullPath[1]."\" />"; 


I find it helpful to use whitespace in my code, Both for indentation and separation. eg. instead of
PHP Code:
if($var == 1){
doSomething();
if(
$var2 == 2){
doSomethingElse;
echo 
"<tr><td><span>text".$var."moretext".$var2."</span></td></tr>";
}} 
something more like
PHP Code:
if($var == 1)
{
    
doSomething();
    if(
$var2 == 2)
    {
        
doSomethingElse;
        echo 
"<tr>
            <td>
                <span>text" 
$var "moretext" $var2 "</span>
            </td>
        </tr>"
;
    }

it makes the code easier to read for me.

BTW, if you put your code inside BBtags, the color syntax highlighting will help.
__________________
WP plugins - Error Reporting, Clean Options
http://www.mittineague.com/dev/er.php
http://www.mittineague.com/dev/co.php

Last edited by Mittineague : March 24th, 2008 at 10:46 PM. Reason: added tip

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Parse errors - Unexpected T_CONSTANT_ENCAPSED_STRING


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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

Iron Speed




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