file_get_contents return & g t; вместо < - PullRequest
0 голосов
/ 06 октября 2011

У меня есть

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

test.html

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

Проблема в том, что file_get_contents возвращает &gt; вместо получения <</p>

Почему?

Я использую wampserver 2 с php 5.3.8

1 Ответ

1 голос
/ 06 октября 2011

Здравствуйте, попробуйте переименовать файл в test.txt, может быть, php автоматически его кодирует для файлов .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

    ?> 
...