我有這個的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的>
而不是讓<
爲什麼?
我使用wampserver 2 PHP 5.3.8
我有這個的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的>
而不是讓<
爲什麼?
我使用wampserver 2 PHP 5.3.8
你好嘗試將文件重命名爲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 "walk" the <b>dog</b> 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
?>
也許你可以給我們一張您試圖檢索的文本。 –
我在示例中添加一個test.html文件以獲得更多的清晰度 –
我試過了你的代碼,它似乎沒問題。對我來說,函數返回「<」字符。你能更清楚地知道你真正看到了什麼嗎?我的意思是......當你迴應這個字符串時,你看到了這個? < div < test </div < –