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

+0

たぶん、あなたは私たちにあなたが取得しようとしているテキストの一部を与えることができます。 –

+0

私はあなたのコードをtryedして、それは大丈夫と思われる例のtest.htmlファイルを追加する –

+0

私にとって、関数は "<" charを返します。あなたは本当にあなたが見ているものをより明示することができますか?ストリングをエコーすると、これが見えますか? < 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

心配しないでください。有りうる。 –

関連する問題