繁体   English   中英

php字符串转换为html

[英]php string convert to html

我有一个字符串<div id="myid"> ... </div>

我如何将其更改为<div id="myid"> ... </div>

我尝试过一些东西,但没有任何帮助吗?

更新

function get_page(){
  $file = 'file.php';
  $str = file_get_contents($file);
  $str = html_entity_decode($str);
  return $str;
}
$output = get_page();
echo $output;//don't work

固定

function get_page(){
      $file = 'file.php';
      $str = file_get_contents($file);
      return $str;
    }
    $output = get_page();
    echo html_entity_decode($output);//works

其功能是htmlspecialchars_decode()

请注意,对于解码引号的函数,您需要指定$quote_style参数。

html_entity_decode是你需要的: httphtml_entity_decode

用这个更好......

<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>

echo strip_tags($text, '<p><a>');
?>
htmlspecialchars_decode($string)
$from = array('&lt;', '&gt;');
$to = array('<', '>');
$string = str_replace($from, $to, $string);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM