Page 1 of 1

why oh why am I getting this parsing error

Posted: Sat Apr 01, 2006 12:18 pm
by bruceg
I don't know where this error is coming from.

"
Parse error: syntax error, unexpected T_VARIABLE in /hsphere/local/home/bruceg/inspired-evolution.com/includes/menu.php on line 34
"

code:

Code: Select all

<?php
$menu = <<<MENU
<ul id="navlist">
<li class="first"><a href="/About_Me.php" title="you know you want to
learn more about me">AboutMe</a></li>
<li><a href="/Skillset.php" title="I've got skillz">Skillset</a></li>
<li><a href="/Hireme.php" title="I can do wonders for your web
presence">Hire Me</a></li>
<li><a href="/Portfolio.php"
title="websites,graphics,newsletters">Portfolio</a></li>
<li><a href="/Contact.php"title="how to get in touch with me">Contact</a></li>
<li><a href="/Resume.php"title="my beautiful
resume">R&eacute;sum&eacute;</a></li>
<li><a href="http://inspiredevolution.blogs.com/inspiredevolutioncom/"title="the
blog of Inspired-Evolution.com">Blog</a></li>
<li class="last"><a href="RSS.php"title="Syndication that is really
simple">RSS</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;
?>
thanks for any clues

hrmm?

Posted: Sat Apr 01, 2006 12:29 pm
by baggypants303
I ran it in Zend and got this:

Parsing error at line 2:: $menu = <<<MENU

Posted: Sat Apr 01, 2006 12:43 pm
by ambivalent

Code: Select all

foreach($linesas$line)
Should not be alloneword.

Posted: Sat Apr 01, 2006 2:15 pm
by bruceg
what's up with line 2? I didn't think whitespacing was an issue in PHP?

Posted: Sat Apr 01, 2006 2:24 pm
by bruceg
is this right?

Code: Select all

for each($lines as $line){

Posted: Sat Apr 01, 2006 2:32 pm
by d3ad1ysp0rk
bruceg wrote:is this right?

Code: Select all

for each($lines as $line){
http://us3.php.net/foreach

Posted: Wed Jun 14, 2006 11:20 am
by bruceg
this worked before, but I am still getting an error this time, the code I now have is:

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>
END;
$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 ($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('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;
?>
looks like the parse error is still coming from END;

Is there a way to achieve the same thing without heredoc syntax?

Posted: Wed Jun 14, 2006 11:52 am
by GM
You shouldn't be using "END;" you should be using "MENU;"

Make sure there is no whitespace before the word MENU.

With heredoc syntax, you finish the string with the same word you started it with:

Code: Select all

$myString = <<<CHEESEGRATER
Hello world, I like cheese.
CHEESEGRATER;

Posted: Wed Jun 14, 2006 1:57 pm
by bruceg
after googling, I found a solution to the problem and if anyone uses DW and possibly the Mac version only and gets this error to resolve it go to preferences/Code format/line break type/change to LF(unix).

works like a charm now :-)

Posted: Thu Jun 15, 2006 8:57 am
by bruceg
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


o.k, so I can get my menu to display without errors, but the CSS isn't working with the page you are on display. I am using the PHP code displayed in previous post for the menu and for the CSS:

#navcontainer ul#navlist li a#current{
border:1px solid red;
}

when I vuew source I just get this:

Code: Select all

<div id="navcontainer">
    <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>
   </div>

so the CSS isn't getting picked up likes it is supposed to via the PHP

I would appreciate any hints or assitance


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Jun 15, 2006 3:22 pm
by bruceg
I have the menu and CSS working now, but there is a small issue. I want to develop my folder structure with a parent directory and child directories so a URL might look like:

http://sitename.com/parent/child1/index.php and http://sitename.com/parent/child2/index.php

with my current intellimenu code I get <li><a id="active"> on all pages inside the parent directory (instead of one)

Is there a way to make the menu more intelligent to determine only one page when the directory is as I am wanting to do?

here is my current code:

Code: Select all

<?php
$menu = <<<MENU
<ul id="nav1">
    <li><a href="/agency/faq/index.php" title="link to FAQ page">FAQ</a></li>
    <li><a href="/points_of_view.php" title="link to Points of View page.">Points of View</a></li>
    <li><a href="/logo.php" title="Link to Logo page">Logo</a></li>
    <li><a href="/process.php" title="Link to Process page">Process</a></li>
    <li><a href="/tour.php" title="Link to Tour page">Tour</a></li>
	</ul>
	<ul id="nav2">
    <li><a href="/creative.php" title="Link to Creative page">Creative</a></li>
    <li><a href="/brand_digital.php" title="Link to Brand digital page">Brand Digital</a></li>
    <li><a href="/agency/direct/index.php" title="Link to Direct page">Direct</a></li>
    <li><a href="/media.php" title="Lin kto Media Page">Media</a></li>
    <li><a href="/public_relations.php" title="Link to Public Relations page">Public Relations</a></li>
    <li><a href="/research_analysis.php" title="Link to Research and Analysis page">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";
}
?>
this creates what I mentioned for FAQ and Direct pages