php
  • wordpress
  • 2011-07-19 38 views 0 likes 
    0

    最後一行中的echo似乎是造成問題。但是我不能拿出來,或者直接打印這行。我怎樣才能重寫那部分?另外,其他PHP函數的寫法有什麼不對嗎?在php代碼中回顯導致問題

    $output .= " 
          <script src='http://platform.twitter.com/widgets.js'></script> 
          <a href='http://twitter.com/share' class='twitter-share-button' 
           data-url='". the_permalink() ."' 
           data-via='username' 
           data-text='". the_title() ."' 
           data-count='horizontal'>Tweet 
          </a> 
          <iframe src='http://www.facebook.com/plugins/like.php?href=". echo urlencode(get_permalink($post->ID)) ."&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;colorscheme=light' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:90px; height:20px;'></iframe>'"; 
    
    +0

    在雙引號前最後一行末尾的額外單引號是什麼?你指的是什麼「問題」? 「我的車在發出奇怪的聲音。 - 哦,它一定是引擎。「 –

    +1

    你爲什麼連接一個回聲?要麼刪除'echo',要麼將其前一個句點改爲分號(';')。 –

    回答

    2

    您應該刪除「回聲」,你不需要它在一個字符串連接:在你的輸出端

    $output .= " 
         <script src='http://platform.twitter.com/widgets.js'></script> 
         <a href='http://twitter.com/share' class='twitter-share-button' 
          data-url='". the_permalink() ."' 
          data-via='username' 
          data-text='". the_title() ."' 
          data-count='horizontal'>Tweet 
         </a> 
         <iframe src='http://www.facebook.com/plugins/like.php?href=". urlencode(get_permalink($post->ID)) ."&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;colorscheme=light' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:90px; height:20px;'></iframe>'"; 
    
    0

    它看起來就像你有一個額外的'(單引號) 。

     
    </iframe>' 
    
    1

    echo不屬於字符串中間。它不返回任何內容,因此在串聯中間沒有任何意義。

    你正在做的連接很長,我相信有一些錯誤。

    最後還有一個額外的單引號。

    您爲iframe構建的網址既包含urlencode,也包含手動轉義&的操作。

    構建網址的更好方法是:http_build_query並讓系統爲您組合。鏈接:http://www.php.net/manual/en/function.http-build-query.php讓系統爲你整合網址幾乎總是更好。由於它位於一堆html的中間,因此你可以在整個事情上運行htmlentitieshttp://www.php.net/manual/en/function.htmlentities.php這將使它適合在html中使用。

    沒有辦法確定其他函數是否不正確,除非您爲它們放置代碼。如果他們總是返回字符串,那就很好。

    如果代碼變得複雜,不要害怕將代碼分解爲多個塊。

    相關問題