2013-11-23 2 views
0

모든 블로그 게시물을 htmlspecialchars으로 보내 모든 문자가 올바르게 표시되도록하려고합니다. 그러나 처리가 완료되면 (데이터베이스에서 데이터를 가져올 때가 아니라 푸시 할 때 호출됩니다) 문자로 표시되지 않습니다! 자신의 재 게시 코드 만 나타납니다. 나는 그것을 밀어 전에 반드시 htmlspecialchars를 사용해야합니다,htmlspecialchars가 브라우저에서 올바르게 렌더링되지 않습니다.

Yay it's working!! 

Everything seems good, comments, url's, random colours etc! 

내 웹 사이트는 또한 jacoblukewood.com 입니다 :

<?php 
    while($result = mysql_fetch_array($results) 
    { 
     echo " 
      <div class=\"post\"><article> 
       <a href=\"//blog.jacoblukewood.com/p/" . $result['id'] . "\"><h3 class=\"posttitle\">" . htmlspecialchars($result['title']) . "</h3></a> 
       <div class=\"postcontent\"> 
       <p>"; 
     if (strlen($result['content']) > 300) 
     { 
      echo nl2br(htmlspecialchars(substr($result['content'],0,300))) . "&hellip; " . "<a href=\"//blog.jacoblukewood.com/p/" . $result['id'] . "\">Continue Reading</a>"; 
     } 
     else 
     { 
     echo nl2br(htmlspecialchars(substr($result['content'],0,300))); 
     } 
     echo "</p> 
      </div> 
     </article> 

     <div class=\"poststats\"> 
      <a href=\"//blog.jacoblukewood.com/p/" . $result['id'] . "#disqus_thread\"></a><a>&nbsp;&bull;&nbsp;By&nbsp;" . $result['poster'] . "&nbsp;&bull;&nbsp;On&nbsp;" . htmlspecialchars(substr($result['timestamp'],0,10)) . "&nbsp;&bull;&nbsp;</a><a href=\"//blog.jacoblukewood.com/t/" . $result['topic'] . "\">" . htmlspecialchars($result['topic']) . "</a><br /></div> 
     </div>"; 
    } 
?> 

그리고 다음과 같이 표시 할 것 : 여기

내가 데이터를 가져 오는거야 어떻게 데이터베이스?

+0

페이지 인코딩을 확인 했습니까 – Satya

+1

데이터를 인코딩하는 것만으로 두 번 나타납니다. – deceze

답변

0

솔직히 나는 데이터베이스의 htmlspecialchars에 대해 걱정할 필요가 없다고 생각합니다. UTF8 문자 세트를 사용하는 경우 대다수의 문자를 사용할 수 있습니다.

이미 데이터베이스에 인코딩 된 문자가있는 경우 http://www.php.net/manual/en/function.htmlspecialchars-decode.php을 사용하면 처리가 취소됩니다.

+0

데이터베이스에 데이터를 삽입하기 전에 데이터를 정리하십시오. 나는 개인적으로이 방법을 사용하고 수년간 가지고있다. function clean_data ($ string) { \t \t $ string = trim ($ string); \t \t if (get_magic_quotes_gpc()) { \t \t \t $ string = stripslashes ($ string); \t \t} \t \t $ string = strip_tags ($ string); \t \t 반환 값 html_entity_decode ($ string, ENT_QUOTES); \t} –

+0

감사합니다. –

관련 문제