我得到一個 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;
請注意,我使用單引號來稍微提高性能,但是當使用雙引號時,模式將是
"/\\n/"
(轉義反斜杠,但即使不轉義也應該工作)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句