我想通过使用我们能够对齐和格式化PHP代码来创建这样的脚本。
目前我有
$conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) { die("Connection failed: " . mysqli_connect_error());}
预期输出:即自动对齐和格式化
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
发布于 2018-08-16 10:41:10
输出:
index.php
<?php
$filename="config.php";
$myfile = fopen($filename, "r") or die("Unable to open file!");
$string= fread($myfile,filesize($filename));
echo "<h3>Before</h3>";
echo '<pre>' . htmlentities($string) . '</pre> <br/>';
$string = str_replace("?php","?php \n",$string);
$string = str_replace("<","<",$string);
$string = str_replace(">",">",$string);
$string = str_replace(">",">",$string);
$string = str_replace("{","{<br/>",$string);
$string = str_replace(";",";<br/>",$string);
$string = str_replace("}","}<br/>",$string);
$string = str_replace("echo"," echo",$string);
//$string = str_replace("$_"," $_<br/>",$string);
echo "<h3>After</h3>";
echo '' . html_entity_decode($string) . '<br/>';
//echo '<pre>' . highlight_string($fileString) . '</pre> <br/>';
fclose($myfile);
?>
还放了一些样式
<style>
pre, code, body{ font-size:13px; font-family:verdana ;line-height: 22px;
text-align: justify;
display: inline-block;
text-justify: inter-word;
text-align: justify;
font-weight: normal !important; }
hr{ border-top: 1px solid #8c8b8b; }
</style>
要格式化的源文件:
<?php $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");echo fread($myfile,filesize("webdictionary.txt"));fclose($myfile);?>
https://stackoverflow.com/questions/-100002205
复制相似问题