gpt4 book ai didi

php - 获取 HTML 内容并将其显示为纯文本

转载 作者:行者123 更新时间:2023-12-05 01:55:29 25 4
gpt4 key购买 nike

我得到一个 html 文件的内容:

ob_start();
include ("myFile.html");
$html = ob_get_contents();

现在我想通过邮件将 $html 作为纯文本发送以显示代码。我试过 "<pre>".$html."</pre>""<code>".$html."</code>"

但我没有得到纯代码。你能帮帮我吗?

最佳答案

尝试这样的事情:

<?php

$filePath = __DIR__ . '/myFile.html';

$content = file_get_contents($filePath);
// Escape.
$content = htmlspecialchars($content);
// Makes lines visible.
$content = preg_replace('/\n/', '<br>' . PHP_EOL, $content);

echo $content;

Note that I use single-quotes to improve performance slightly, but when using double-quote, the pattern would be "/\\n/" (to escape Back-slash, but should work even without escaping).

关于php - 获取 HTML 内容并将其显示为纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70203454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com