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

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 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);
    }