2011-10-06 9 views
0

file_get_contents는 <대신 & g t ;을 반환합니다.

 $this->CompileString_ = file_get_contents("test.html"); 
echo $this->CompileString_; 

test.html

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

문제는 file_get_contents가 <을받는 대신 &gt;을 반환한다는 것입니다.

왜?

나는 PHP 5.3.8

와 wampserver 2를 사용하고있다.
+0

사용은 아마 당신은 우리에게 당신이 검색하려는 텍스트의 일부를 제공 할 수 있습니다. –

+0

예제에서 더 명확하게 test.html 파일을 추가합니다. –

+0

코드를 tryed했지만 괜찮을 것 같습니다. 나에게 함수는 "<"문자를 반환합니다. 당신이 실제로 보는 것에 대해 더 명백하게 나타낼 수 있습니까? 내 말은 ... 끈을 에코 할 때, 이거 보여? < div < 시험 </div < –

답변

1

안녕하세요 어쩌면 자동으로 PHP는 test.txt에 파일의 이름을 변경 시도와 wampserver 2를 사용하고는 인코딩 .html 중에서 파일이. htmlentitydecode();

<?php 
    $orig = "I'll \"walk\" the <b>dog</b> now"; 

    $a = htmlentities($orig); 

    $b = html_entity_decode($a); 

    echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now 

    echo $b; // I'll "walk" the <b>dog</b> now 


    // For users prior to PHP 4.3.0 you may do this: 
    function unhtmlentities($string) 
    { 
     // replace numeric entities 
     $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); 
     $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); 
     // replace literal entities 
     $trans_tbl = get_html_translation_table(HTML_ENTITIES); 
     $trans_tbl = array_flip($trans_tbl); 
     return strtr($string, $trans_tbl); 
    } 

    $c = unhtmlentities($a); 

    echo $c; // I'll "walk" the <b>dog</b> now 

    ?> 
+0

당신이 틀린 질문에 대답했다고 생각합니다. OP는 문자를 디코드하고 인코딩하지 않기를 원합니다. –

+0

@AurelioDeRosa 죄송합니다. – Mob

+0

걱정하지 마십시오. 그것은 일어날 수있다. –

관련 문제