Perplexed
Perplexed

Reputation: 877

php include files

Hello from a complete newbie to PHP5.

I created a header file (html) which contains navigation links.

In another page (index.php) I put an include in the body of the page.

The index page has a link to a css file which styles the navigation links in the include file.

When I view the page, the part where the include is made contains garbled characters (well mostly diamond chars with ? inside).

If I replace the header file with a simplified one with only one div block it displays fine. So I suspect that the include file does not like the style sheet references?!?

I would appreciate it if someone could shed some light on this.

Many thanks,

KS

<div id="header">
<div id="menu">
  <ul id="nav-one" class="nav">
    <li>
      <a href="#">About Us</a>
      <ul>
        <li><a href="about-wcjja.html">About WCJJA</a></li>
        <li><a href="about-wing-chun.html">Wing Chun</a></li>
        <li><a href="history-of-wing-chun.html">History</a></li>
        <li><a href="new.html">What's New</a></li>
        <li><a href="wing-chun-links.html">Links</a></li>
      </ul>
    </li>
    <li>
      <a href="#">Instructors</a>
      <ul>
        <li><a href="marvon-wilkinson.html">Marvon Wilkinson</a></li>
        <li><a href="lineage.html">Lineage</a></li>
      </ul>
    </li>
    <li>
      <a href="#">Classes</a>
      <ul>
        <li><a href="wing-chun-classes.html">Wing Chun</a></li>
        <li><a href="womens-self-defense.html">Women's Self Defense</a></li>
        <li><a href="workshops.html">Seminars &amp; Workshops</a></li>
      </ul>
    </li>
    <li>
      <a href="#item2">Media</a>
      <ul>
        <li><a href="gallery.html">Gallery</a></li>
        <li><a href="videos.html">Video</a></li>
        <li><a href="more-wc.html">More Wing Chun</a></li>
      </ul>
    </li>
    <li>
      <a href="#">Contact Us</a>
      <ul>
        <li><a href="email-us.html">Email Us</a></li>
        <li><a href="schools.html">School Locations</a></li>
        <li><a href="bookmark-us.html">Bookmark us</a></li>
        <li><a href="copyright.html">Copyright</a></li>
      </ul>
    </li>
  </ul>
</div>
</div>

Upvotes: 1

Views: 193

Answers (4)

David Ly
David Ly

Reputation: 31596

The problem is that there are 2 different encodings in the source, and a page may only declare one encoding.

When I view source in Firefox on the header section this is what I see:

��<�d�i�v� �i�d�=�"�h�e�a�d�e�r�"�>�

The format of the header file is probably some double-byte format, maybe UTF-16 maybe something else, but the rest of the page is in UTF-8.

Use a text editor that allows you to choose the encoding of the (header) file and save that file as UTF-8 and that should fix your problem.

Upvotes: 1

Racooon
Racooon

Reputation: 1496

Just put this code in your .htaccess, you will use utf-8 always anyway.

.htaccess

AddType text/html;charset=utf-8 .html

OR

btw. if u should use XHTML, u would not get an utf-8 problem. set your doctype as xhtml and transitional, it will be utf-8 for all pages automatically.

 <?php header("Content-Type: text/html; charset=utf-8"); ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">

these tags will save you anytime.

Upvotes: -1

webbiedave
webbiedave

Reputation: 48897

Ensure your content-type header is correct.

You can try:

<meta http-equiv="content-type" content="text/html; charset=utf-8">

(delete any other content-type headers that may exist)

Upvotes: 1

jeroen
jeroen

Reputation: 91734

Sounds like a character encoding issue, what format are your files in? I´d recommend putting everything in utf8

Upvotes: 2

Related Questions