php字符串转换为html

发布于 2024-10-04 08:35:56 字数 673 浏览 1 评论 0原文

我有一个字符串 <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

I have a string <div id="myid">...</div>

How would I change this into
<div id="myid">...</div>

I have tried a few things but no luck any help?

Update

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

FIX

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

月下伊人醉 2024-10-11 08:35:56

其函数是 htmlspecialchars_decode()

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

The function for that is htmlspecialchars_decode().

Note that for the function to decode quotes, you need to specify the $quote_style parameter.

牵你的手,一向走下去 2024-10-11 08:35:56
$from = array('<', '>');
$to = array('<', '>');
$string = str_replace($from, $to, $string);
$from = array('<', '>');
$to = array('<', '>');
$string = str_replace($from, $to, $string);
作死小能手 2024-10-11 08:35:56

用这个更好...

<?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>');
?>

use this it's better ...

<?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>');
?>
善良天后 2024-10-11 08:35:56
htmlspecialchars_decode($string)
htmlspecialchars_decode($string)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文