Jump to content

Another Parse Error.....


krysco

Recommended Posts

I'm trying to do something really simple and I can't quite figure out how. I want to use php to include my header document the best way possible. I want it to pull in another "page" that has the code for my document top in it. I tried three ways (none of them worked). I tried creating a page called header.php with the document in it that looked like the following.

<html>
<body>
<img src="images/includes/headers/header.php">
</body>
</html>

 

That didn't work so I tried this.

<html>
<body>
<img src="<?php echo('./includes/headers/header.php')">
</body>
</html>

 

That didn't work either. So tried both again this time using a .html extension instead of php......nope. So then I tried using just the jpeg itself....

<?php include('./includes/headers/images/header.jpg')?>

I got a parse error:

Parse error: syntax error, unexpected T_STRING in /var/www/includes/headers/images/header.jpg on line 39

 

Ummmmmm why is there a line 39 in a jpeg image??? I have no idea what I'm doing or what to try next. Help!

Link to comment
Share on other sites

You're probably confused because I don't really know what I'm doing and I sort of lost track of what I did. I'm not so much concerned as fixing what's wrong as I am with doing what's right or what works. What I am trying to achieve is this. I want to have a page with my header on it. I want to be able to include that page at the top of the rest of the pages in my site so that if I want to change the header I only have to change it in one place. I am also going to use this method for my nav menu. What would be the best way to do it? When I used to do it with coldfusion it was as simple as creating an html page without the html and body tags (just a table) and throwing a cf include function at the top of every page. How would I do that?

Link to comment
Share on other sites

You're probably confused because I don't really know what I'm doing and I sort of lost track of what I did. I'm not so much concerned as fixing what's wrong as I am with doing what's right or what works. What I am trying to achieve is this. I want to have a page with my header on it. I want to be able to include that page at the top of the rest of the pages in my site so that if I want to change the header I only have to change it in one place. I am also going to use this method for my nav menu. What would be the best way to do it? When I used to do it with coldfusion it was as simple as creating an html page without the html and body tags (just a table) and throwing a cf include function at the top of every page. How would I do that?

ok, so the header is basically HTML, right?

if so, then doing this includes files:

<?php
include("include_file.php");
?>
<!-- continue as normal --!>

Link to comment
Share on other sites

Example:

 

./index.php

./includes/headers/header.php

./includes/headers/images/header.jpg

 

index.php

<body>
<?php include "includes/headers/header.php"; ?>
</body>

 

header.php

<img src = '/includes/headers/images/header.jpg' />

 

if all header.php is doing is echoing out html, you can rename it header.html.   

Link to comment
Share on other sites

no.  Those would be in index.php.  When you include one thing in another, it's just like copy/pasting it inside it.  When you request index.php, it is the same as it being this (minus the comments; i put them there for notes):

 

<body> // came from index.php
<img src = '/includes/headers/images/header.jpg' /> // came from header.html/php
</body> // came from index.php

Link to comment
Share on other sites

That didn't work either. I'm on the computer I was having the problem with. When I open the page in firefox, everything works except the header. It only shows the background color I set in my CSS. These are the two files I'm working with.

 

index.php

<!DOCTYPE html PUBLIC "-//w3C//DTD XHTML 1.0 Strict//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>CSS Practice</title>
    <link href="includes/css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
    <div id="container">
            <div id="pageHeader">
               <?php include('./includes/headers/header.html');?>
            </div>

        <div id="contentContainer">
            <div id="content">
                <p>Content</p>
            </div>
        </div>
        <div id="sidebarContainer">
            <div id="navcontainer">
                <ul>
                    <li><a href="testcss.html" id="current>Page 1</a></li>
                    <li><a href="http://www.google.com">Page 2</a></li>
                    <li><a href="http://www.yahoo.com">Page 3</a></li>
                    <li><a href="http://www.altavista.com">Page 4</a></li>
                </ul>
            </div>            
        </div>
        <div id="footer" class="clearer">
            <p>Footer</p>
        </div>
    </div>
</body>
</html>

 

header.html

<img src="/images/header.jpg">

 

Link to comment
Share on other sites

yes i understand how that works. the file path i used is relative to where the document lies coupled with the fact that the index page is at the site root. is there a command i can use to get directly back to the site root? i know with cf it was a complicated string of like ./../../../../../../../../ lol

Link to comment
Share on other sites

i tried that too. the only thing that seems to work is having the header image and the header html page in the same folder as the index page. is there something like a BASE HREF that I could use. i remember something like that in coldfusion but i don't remember how it worked. could the problem be that i'm using a VM (doubt it). i have it set up so that my VM gets the same ip address as the host machine. i don't think that would cause a problem since when i tried the absolute url i used http://localhost. that should take it to my site root. but anybody know anything about the BASE HREF?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.