首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP-如何创建PHP代码格式化程序和美化器?

PHP-如何创建PHP代码格式化程序和美化器?
EN

Stack Overflow用户
提问于 2018-08-16 00:55:43
回答 1查看 0关注 0票数 0

我想通过使用我们能够对齐和格式化PHP代码来创建这样的脚本。

目前我有

代码语言:txt
复制
$conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) {  die("Connection failed: " . mysqli_connect_error());}

预期输出:即自动对齐和格式化

代码语言:txt
复制
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
EN

回答 1

Stack Overflow用户

发布于 2018-08-16 10:41:10

输出:

index.php

代码语言:txt
复制
<?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("<","&#x3C",$string);
$string = str_replace(">","&#x3E",$string);
$string = str_replace(">","&#x3E",$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("$_","&nbsp; $_<br/>",$string);

echo "<h3>After</h3>";
echo '' . html_entity_decode($string) . '<br/>';

//echo '<pre>' . highlight_string($fileString) . '</pre> <br/>';

fclose($myfile);
?> 

还放了一些样式

代码语言:txt
复制
<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>

要格式化的源文件:

代码语言:txt
复制
 <?php $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");echo fread($myfile,filesize("webdictionary.txt"));fclose($myfile);?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档