not sure why I am getting parsing error with heredoc

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

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

not sure why I am getting parsing error with heredoc

Post 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
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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?
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

yea, It is the MENU; line I believe. I will double check for extra spaces
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

What about spaces after MENU; ?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

No spaces are showing up in DW
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

Haven't we been here before?

Code: Select all

foreach($linesas$line){
http://forums.devnetwork.net/viewtopic.php?t=46455
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You already have a thread on the same problem from 2 momths ago...use that

Image
Locked