parse error, unexpected T_Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

parse error, unexpected T_Variable

Post by bruceg »

I get an error on line 9 of the below code (the line beginning with $str)

'parse error, unexpected T_Variable'.

I'm pretty new to PHP programming and not sure what's wrong with that line...any suggestions?

Code: Select all

<?php 

function breadcrumb_nav($basename = "Home") { 

   global $PHP_SELF, $bc_site, $bc_label; 

   $site = $bc_site; 
   $return_str = "<A HREF=/"//">$basename</A>"; 
   $str = substr(dirname($PHP_SELF), 1); 

   $arr = split('/', $str); 
   $num = count($arr); 

   if ($num > 1){ 

      foreach($arr as $val) { 

         $return_str .= ' > <a href="'.$site.$val.'/">'.$bc_label[$val].'</a>'; 
         $site .= $val.'/'; 

      } 

   } elseif($num == 1) { 

      $arr = $str; 
      $return_str .= ' > <a href="'.$bc_site.$arr.'/">'.$bc_label[$arr].'</a>'; 

   } 

   return $return_str; 

} 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. if you want a double quote in a double quote string, it must be escaped. i.e.

    Code: Select all

    &quote;this is a double quote string with some \&quote;double quotes\&quote; in it&quote;;
  2. line 8 also has //, which is a single line comment in php. So the line isn't being terminated by the semicolon. i.e. php sees the following

    Code: Select all

    $return_str = &quote;&lt;A HREF=/&quote;
       $str = substr(dirname($PHP_SELF), 1);
rochakchauhan
Forum Newbie
Posts: 5
Joined: Tue Apr 26, 2005 4:32 am

Just replace this

Post by rochakchauhan »

On Line 8:

write this

Code: Select all

$return_str = '<A HREF=/>$basename</A>';
Post Reply