Page 1 of 1

parse error, unexpected T_Variable

Posted: Fri Apr 15, 2005 1:01 pm
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; 

} 
?>

Posted: Fri Apr 15, 2005 1:54 pm
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);

Just replace this

Posted: Tue Apr 26, 2005 6:30 am
by rochakchauhan
On Line 8:

write this

Code: Select all

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