php Bin2PHP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Bin2PHP相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> bin2php<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input_file</span>, <span style="color: #0000ff;">$output_file</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$i</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input_file</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$b</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$x</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$y</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$c</span>=<span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$c</span> < <a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$c</span>++<span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$no</span> = <a href="http://www.php.net/bin2hex"><span style="color: #000066;">bin2hex</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$c</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$b</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">]</span> = <a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$b</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span> ? <span style="color: #0000ff;">$b</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">]</span>.<span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>x'</span>.<span style="color: #0000ff;">$no</span> : <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>x'</span>.<span style="color: #0000ff;">$no</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$y</span> >= <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$x</span>++; <span style="color: #0000ff;">$y</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #0000ff;">$y</span>++;
<span style="color: #66cc66;">}</span>
<span style="color: #0000ff;">$output</span> = <span style="color: #ff0000;">"<"</span>.<span style="color: #ff0000;">"?php<span style="color: #000099; font-weight: bold;">\n</span>"</span>;
<span style="color: #0000ff;">$output</span> .= <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\$</span>f=<span style="color: #000099; font-weight: bold;">\"</span>"</span>;
<span style="color: #0000ff;">$output</span> .= <a href="http://www.php.net/implode"><span style="color: #000066;">implode</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\"</span>;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\$</span>f.=<span style="color: #000099; font-weight: bold;">\"</span>"</span>, <span style="color: #0000ff;">$b</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$output</span> .= <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\"</span>;<span style="color: #000099; font-weight: bold;">\n</span>print <span style="color: #000099; font-weight: bold;">\$</span>f;"</span>;
<span style="color: #0000ff;">$output</span> .= <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>?>"</span>;
<span style="color: #0000ff;">$fp</span> = <a href="http://www.php.net/fopen"><span style="color: #000066;">fopen</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$output_file</span>, <span style="color: #ff0000;">'w+'</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/fwrite"><span style="color: #000066;">fwrite</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$fp</span>, <span style="color: #0000ff;">$output</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/fclose"><span style="color: #000066;">fclose</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$fp</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span>
以上是关于php Bin2PHP的主要内容,如果未能解决你的问题,请参考以下文章
php [guzzle php] guzzle php #php
IntelliJ IDEA 11编辑php是,支持php文件名为.php5和.php4,如何设置能让其也支持.php呢?