惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - rainbow727

ps-图层调整大小 js 根据关键字,进行mark背景色标记 时间戳转换为时间格式 ps-图层尺寸缩放 ps-窗口缩放比例调整 bug Extjs小例子 ps-填充色 jq 数组对象,重复数据进行合并 ipv4,ipv6起止地址判断,网段判断 HTML li标签排列有空白间隙 Ext.js知识点纪要 知识点小纪要 function函数 常用正则表达式 正则表达式的字符含义 邮箱正则表达式 jQuery相关面试题 js继承
PHP 文件内容处理
rainbow727 · 2018-02-26 · via 博客园 - rainbow727

1.implode(将数组元素组合成字符串)

  $file = ''/tmp/httpProxyLog.csv'';

   $arr = array('qq','ww','1.1',"","");

    $arr = array_filter($arr);//过滤掉多余的空格元素;
         $str =  implode(",",$arr);//将数组以逗号组合成字符串。

  exec("echo \"$str\" >> \"$file\"","",true);//将字符串追加到文件中;

   $fp = fopen($file, 'w');
       fputcsv($fp,$arr);   //fputcsv()可以用数组循环的方式进行实现,写入csv文件
       fclose($fp);

2.explod(把字符串打散为数组)

$str = "Hello    world     I love Shanghai";
$str = preg_replace("/\s(?=\s)/","\\1",$str);//去掉多余的空格,只留一个空格; $arr = explode(" ",$str);//然后以空格分割成数组;
echo $arr ;

或者

$str = "Hello     world    I love Shanghai";
$arr = explode(" ",$str);//然后以空格分割成数组;
$arr = array_filter($arr);//过滤掉多余的空格;
echo $arr;

3.

文件修改
$filename = "/tmp/conntrack";
        $line = 5;//修改的行数
        //要替换的参数
        $replace['search'] = "a";
        $replace['replace'] = "b";
        $fp=fopen($filename,'r+');
        $result="";
        
        if($fp){
            $i=0;
            while($str=fgets($fp)){
                $i++;
                if($i==$line){
                    $str=str_replace($replace['search'],$replace['replace'],$str);
                }
                $result.=$str;
            }
            file_put_contents($filename,$result);
            fclose($fp);
        }
4.将数组元素写入文件

$file_path = '3.txt';
    $con_array = array(array('tcp','close','1.1.1.1'),array('tcp','close','1.1.1.2'));
    
    foreach($con_array as $conntrack){
        $con = implode(" ", $conntrack);//组合回字符串
      file_put_contents($file_path, $con.PHP_EOL,FILE_APPEND);
    }