2012-08-09 24 views
0

打亂佈局,我一個網站here意外引號在PHP網頁

的工作我使用的index.php和「包括」在網站的各個頁面拉。我看到的問題是,當主頁加載時,會有兩個引號將主內容壓下。奇怪的是,當你點擊任何其他頁面時(甚至'Home'鏈接),它們消失並且事情恢復正常。

Here你可以使用Chrome的檢查元素工具中看到的標記中的引號:

這是從的index.php代碼:

<?php include('header.php') ?> 
<div id="acontainer"> 
    <?php include('homepage.php') ?> 
</div> 
<?php include('footer.php') ?> 

這是菜單,該代碼加載不同的PHP文件到#acontainer:

<ul> 
     <li><a class="menui" href="#" onclick="$('#acontainer').load('homepage.php');return false;"><span>Home</span></a></li> 
     <li><a class="menui" href="#" onclick="$('#acontainer').load('tuition.php');return false;"><span>Tuition</span></a></li> 
     <li><a class="menui" href="#" onclick="$('#acontainer').load('about.php');return false;"><span>About Me</span></a></li> 
     <li><a class="menui" href="#" onclick="$('#acontainer').load('contact.php');return false;"><span>Contact Me</span></a></li> 
     <li><a class="menui" href="#" onclick="$('#acontainer').load('faq.php');return false;"><span>FAQ</span></a></li> 
    </ul> 

這是homepage.php代碼:

<script type="text/javascript"> 

$(function(){ 
    $('#slideshow').cycle({ 
     fx:  'fade', 
     speed: 'slow', 
     timeout: 12000, 
     pager: '#slider_nav', 
     pagerAnchorBuilder: function(idx, slide) { 
      // return sel string for existing anchor 
      return '#slider_nav li:eq(' + (idx) + ') a'; 
     } 
    }); 
}); 

</script> 
<div class="header_blog"> 
    <div id="slider"> 
     <!-- start slideshow --> 
     <div id="slideshow"> 
     <div class="slider-item"><a href="#" onClick="$('#acontainer').load('tuition.php');return false;"><img src="images/simple_img_1.jpg" alt="icon" width="917" height="398" border="0" /></a></div> 
     <div class="slider-item"><a href="#" onClick="$('#acontainer').load('about.php');return false;"><img src="images/simple_img_2.jpg" alt="icon" width="917" height="398" border="0" /></a></div> 
     <div class="slider-item"><a href="#" onClick="$('#acontainer').load('tuition.php');return false;"><img src="images/simple_img_3.jpg" alt="icon" width="917" height="398" border="0" /></a></div> 
     <div class="slider-item"><a href="#" onClick="$('#acontainer').load('contact.php');return false;"><img src="images/simple_img_4.jpg" alt="icon" width="917" height="398" border="0" /></a></div> 
     </div> 
     <div class="clr"></div> 
     <!-- end #slideshow --> 
     <div class="controls-center"> 
     <div id="slider_controls"> 
      <ul id="slider_nav"> 
      <li><a href=""></a></li> 
      <!-- Slide 1 --> 
      <li><a href=""></a></li> 
      <!-- Slide 2 --> 
      <li><a href="#"></a></li> 
      <!-- Slide 3 --> 
      <li><a href="#"></a></li> 
      <!-- Slide 4 --> 
      </ul> 
     </div> 
     <div class="clr"></div> 
     </div> 
     <div class="clr"></div> 
    </div> 
    <div class="clr"></div> 
    <div class="FBG"> 
     <div id="quote"> 
     <p> 
     Welcome to <strong>Creative Tuition</strong>, home of personal guitar tuition for musicians of all ages and abilities around the North West of England. Book a free lesson today! 
     </p> 
     </div> 
     <div class="clr"></div> 
    </div> 

    <div class="FBG" style="border-bottom : none;"> 

     <div id="reasons-list"> 

      <h3 class="level">3 Reasons to Give Creative Tuition a Try</h3> 
      <br /> 
      <ul id="reasons"> 
       <li>Your first lesson is FREE and includes a complete breakdown of where you are and where you want to be</li> 
       <li>5 years of professional teaching experience and Grade 8: Rock Guitar Playing & Theory</li> 
       <li>Creative and custom lesson plans completely tailorered for YOU</li> 
      </ul> 

      <p>Not enough? Find out more at our <a href="#" onClick="$('#acontainer').load('tuition.php');return false;">Tuition Page</a>.</p> 
      <div class="clr"></div>.</p> 

     </div> 

     <div id='mediaspace'>This text will be replaced</div> 

     <div id="reasons-video"> 
      <script type='text/javascript'> 
       jwplayer('mediaspace').setup({ 
       'flashplayer': 'js/player.swf', 
       'author': 'Creative Guitar Tuition', 
       'file': 'http://www.youtube.com/watch?v=RyXTJkLRSEg', 
       'controlbar': 'bottom', 
       'width': '470', 
       'height': '320' 
       }); 
      </script> 

     </div> 
       <h3 class="level">Is Creative Guitar Tuition right for you?</h3> 
       <br /> 
       <p>The creative and flexible lesson plan taught at Creative Guitar Tuition was developed through <span class="blue">5 years of professional teaching experience</span> at many of the UK’s major guitar outlets and institutions. This tried and tested teaching method not only includes the best content you will find but (and this is the key), through careful dissection of your ability and goals, we will work together to create a completely customised lesson plan. This will ensure your musical progression does not deviate from your desired path to becoming a better musician. This will ensure you arrive at your musical destination in the shortest, most efficient and fun way possible.</p> 
     <br /> 
     <div id="level"> 
      <div class="fourth"> 
       <h3>Beginner?</h3> 
       <p>Are you just beginning your musical journey? Are you short on spare time and tired of trawling the Internet only to find hit and miss information?</p> 
      </div> 
      <div class="fourth"> 
       <h3>Intermediate?</h3> 
       <p>Are you at intermediate level but feel that you're progression isn’t moving as fast and in the direction you’d like?</p> 
      </div> 
      <div class="fourth"> 
       <h3>Advanced?</h3> 
       <p>Are you an advanced player, but you’ve hit a wall and you're not sure how to push on to the next level?</p> 
      </div> 
      <div class="fourth"> 
       <h3>Not sure?</h3> 
       <p>No matter what your ability, Creative Guitar Tuition will give you a free lesson so you can see just how much better you could be.</p> 
      </div> 
      <a class="free-lesson" href="#" onClick="$('#acontainer').load('contact.php');return false;" /> 
     </div> 

    </div> 
    </div> 
      </div> 

任何線索是什麼導致這個奇怪的行爲?

非常感謝

+3

「homepage.php」中有什麼 – 2012-08-09 17:51:26

+0

homepage.php中的代碼是什麼? – Stegrex 2012-08-09 17:51:30

+2

如果您的任何腳本以PHP代碼結尾,請確保沒有關閉'?>'標籤。這可能會導致此類問題。 – Matt 2012-08-09 17:52:50

回答

2

您看到的「引號」只是單個空格的顯示。由於空格爲空,開發人員工具無法顯示空格。爲了向您展示空間,開發人員工具使用引號。

解決方法是在每個包含文件的最終?>之後刪除空格和換行符,或者甚至更好,只是省略最後的?>。這是PHP允許的,並且受到許多開發人員的鼓勵,以避免您遇到的確切問題。

其他不需要的空間來源是><之間的空格或換行符。這些並不總是很容易找到或解決。我給你一個評論

<div id="acontainer"><?php include('homepage.php') ?></div> 

在一行上。這適用於這裏,但在更復雜的情況下,您需要空間和換行以提高可讀性。在這種情況下把換行符>?>這樣之前(這是允許的HTML和PHP!):

<div id="acontainer" 
    ><?php include('homepage.php') 
    ?></div> 

但這樣做只是如果你真的有不必要的空間問題。大多數時候空間是良性的。

+0

我試過刪除'?> index.php中的三個包含文件,但我得到了解析錯誤。我不是100%確定哪個'?>'我正在刪除,對不起。 – Audity 2012-08-09 18:11:55

+0

也許'<?php include的縮進('homepage.php')?>'會導致問題。 – nalply 2012-08-09 18:16:50

+0

感謝您的建議,雖然我嘗試過,但沒有解決它。 – Audity 2012-08-09 19:47:07

0

我在尋找相同問題的幫助。什麼幫助我將文件編碼爲「沒有BOM的UTF-8」(Notepad ++有這個選項)。如果您的文件使用UTF-8進行編碼,那麼最有可能導致此問題。希望它能幫助那些在這個線程上絆倒的人。