我需要以这种格式将文件记录到文件中:
<style>
.navbar-brand.navbar-center {
position: absolute;
left: 50%;
display: block;
text-align: center;
padding: 0px;
}
.navbar-toggle {
z-index:3;
}
</style>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class=""><a href="#">Profile</a></li>
<li class=""><a href="#">My Home</a></li>
<li><a href="#">Administration</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Reporting <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<a class="navbar-brand navbar-center" href="http://disputebills.com"><img height="78" width="78" style="margin-right: 10px; padding: 0;" src="https://res.cloudinary.com/disputebills/image/upload/v1462474206/blue-mark_cnzgry.png" alt="Dispute Bills">
</a>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
我该怎么做?
答案 0 :(得分:0)
我认为你要搜索的是file_put_contents:
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
似乎易于使用。但是,似乎传递一个数组没有保留密钥,我会使用json_encode($ data)来保持结构的完整。
file_put_contents($ filename,json_encode($ data))
我在logfile中获得的例子:
{"[Date]":"Thu, 15 Jun 2017 13:06:37 GMT","[Server]":"Apache\/2.4.18 (Win32) OpenSSL\/1.0.2f PHP\/5.6.18","[X-Powered-By]":"PHP\/5.6.18","[Content-Length]":"7790","[Content-Type]":"application\/json; charset=utf-8"}
此方法的优点是,如果您愿意,可以轻松地将其从日志文件重新转换为数组。
好吧,找到了另一种更简单的方法:
file_put_contents ( $filename , print_r($data, true));
即使将格式化后放入文件中也会保留格式。
例如:
Array
(
[Date] => Thu, 15 Jun 2017 13:06:37 GMT
[Server] => Apache/2.4.18 (Win32) OpenSSL/1.0.2f PHP/5.6.18
[X-Powered-By] => PHP/5.6.18
[Content-Length] => 7790
[Content-Type] => application/json; charset=utf-8
)