Page 1 of 1

not sure why I am getting parsing error with heredoc

Posted: Wed Jun 14, 2006 9:19 am
by bruceg
the code

Code: Select all

<?php
$menu = <<<MENU
<ul id="navlist">
<li><a href="#" title="link to Frequently Asked Questions section">FAQ&acute;s</a></li>
<li><a href="#" title="link to Points of View section">Points of View</a></li>
<li><a href="#" title="link to Logo section">Logo</a></li>
<li><a href="#" title="link to Process section">Process</a></li>
<li><a href="#" title="link to Tour section">Tour</a></li>
</ul>

<ul id="navlist2">
<li><a href="#" title="link to creative section">Creative</a></li>
<li><a href="#" title="link to Brand Digital section">Brand Digital</a></li>
<li><a href="#" title="link to Direct section">Direct</a></li>
<li><a href="#" title="link to Media section">Media</a></li>
<li><a href="#" title="link to Public Relations section">Public Relations</a></li>
<li><a href="#" title="link to Research Analysis section">Research & Analysis</a></li>
</ul>
MENU;

$lines = split("\n", $menu);
foreach ($lines as $line) {
$current = false;
preg_match('/href="([^"]+)"/', $line, $url);
if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) {
$line = str_replace('<a h', '<a id="current" h', $line);
}
echo $line."\n";
}


//belowthevariant:

foreach($linesas$line){
$current=false;
preg_match('/href="([^"]+)"/',$line,$url);
if(substr($_SERVER["REQUEST_URI"],0,5)==substr($url[1],0,5)){
$line=str_replace('ah','aid="current"h',$line);
if($_SERVER["REQUEST_URI"]==$url[1])
$line=preg_replace('|href=".*?"|','',$line);
$pagetitle=preg_replace('/<[^>]+>/','',$line);
echo$line;
}else{
echo$line."\n";
}
}
echo'<br />'.$pagetitle;
?>
the error :


Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/vhosts/sandbox/rbwulanguzicom.dv/lib/php/menu.php on line 19

any assistance is greatly appreciated

Posted: Wed Jun 14, 2006 9:23 am
by bdlang
Which line is 19? The closing MENU attribute? Do you have any indentation at all on that line? Even a single space before the closing MENU will cause an error. Have you tried using simply END?

Posted: Wed Jun 14, 2006 9:33 am
by bruceg
yea, It is the MENU; line I believe. I will double check for extra spaces

Posted: Wed Jun 14, 2006 9:44 am
by bruceg
I don't have a space before MENU; and tried END; and I am still getting the parse error,

any other thoughts? The error is definitely on that line though. I am not using a php editor, using DW.

Posted: Wed Jun 14, 2006 10:07 am
by pickle
What about spaces after MENU; ?

Posted: Wed Jun 14, 2006 10:28 am
by bruceg
No spaces are showing up in DW

Posted: Wed Jun 14, 2006 10:59 am
by ambivalent
Haven't we been here before?

Code: Select all

foreach($linesas$line){
http://forums.devnetwork.net/viewtopic.php?t=46455

Posted: Wed Jun 14, 2006 11:17 am
by JayBird
You already have a thread on the same problem from 2 momths ago...use that

Image