I'm a complete PHP noob, and so I don't know how to troubleshoot this myself. I found this page which I'm trying to implement: http://webdevjunk.com/coding/css/17/php-menu-includes-with-css-style-to-highlight-active-page-link/
I tried to put the snippets into http://www.paulgrantdesign.com/test77/photography/index.php and /test77/photography/includes/nav.php
Why does my index.php say that there's an unexpected "="?
I'd really appreciate the help :)
EDIT: As requested, here's the PHP that's throwing the err开发者_运维问答or
<?php $active[$current] = “class=active”; ?>
<div id="nav">
<ul>
<li <?php echo $active[1] ?>><?php if ($current != 1) { echo “<a href="index.php">Home</a>”; } else { echo “Home”; } ?></li>
<li <?php echo $active[2] ?>><?php if ($current != 2) { echo “<a href="about.php">About</a>”; } else { echo “About”; } ?></li>
<li <?php echo $active[3] ?>><?php if ($current != 3) { echo “<a href="how_it_works.php">How it works</a>”; } else { echo “How it works”; } ?></li>
There's more, but that gives you the idea of where it's going. Each page on the website has the identifier to say which menu item it's identifying. The identifier looks like this:
<?php $current = 3; include ('includes/nav.php'); ?>
Your first PHP lesson:
- Do not copy and paste :) Type in
$active[$current] = "class=active";
instead of copying and pasting it. In fact, I think you will learn more when you type it out.
By the way, the curly quote “ ”
is what caused the error.
Looks like line 1 has curly quotes:
“class=active”
You need to change them to normal quotes
"class=active"
Also you have to escape quotes within quotes or rather use single quotes instead:
<?php $active[$current] = "class=active"; ?>
<div id="nav">
<ul>
<li <?php echo $active[1] ?>><?php if ($current != 1) { echo '<a href="index.php">Home</a>'; } else { echo 'Home'; } ?></li>
<li <?php echo $active[2] ?>><?php if ($current != 2) { echo '<a href="about.php">About</a>'; } else { echo 'About'; } ?></li>
<li <?php echo $active[3] ?>><?php if ($current != 3) { echo '<a href="how_it_works.php">How it works</a>'; } else { echo 'How it works'; } ?></li>
The code in the linked article is slightly damaged. PHP uses normal double quotes ("
) but the article features invalid typographic quotes (“
and ”
).
You have to use the "
character instead of “
and ”
.
精彩评论