php换行符

2019-04-17 22:38:54

使用str_replace 来替换换行  

$str = str_replace(array("\r\n", "\r", "\n"), "", $str);   


2、使用正则替换  

$str = preg_replace('//s*/', '', $str);  


3、使用php定义好的变量 (建议使用)  

$str = str_replace(PHP_EOL, '', $str);   


php字符串加回车注意事项

php添加回车 注意事项 "\n\t" ,注意一定要用双引号,单引号直接输出这个字符。



$data = preg_replace_callback('/(([\n\r])\S+?(jpg))/', function ($matches) {

   /*为了设置图片有效期为当天*/

 //  error_log(json_encode($matches));
   $http = "http://demo.sadfasf.com/a/";
   $href = $http.$matches[0];
   $href = str_replace(array("\r\n", "\r", "\n"), "", $href);
   $href =  DTools::getQiniuAntiLeechAccessUrlBasedOnTimestamp($href);


   return "\r\n" .$href;
}, $data);



  • 2021-05-25 13:10:49

    npm 多个不同版本的依赖

    提起 npm,大家第一个想到的应该就是 npm install 了,但是 npm install 之后生成的 node_modules 大家有观察过吗?package-lock.json 文件的作用大家知道吗?除了 dependencies 和 devDependencies,其他的依赖有什么作用呢?接下来,本文将针对 npm 中的你可能忽略的细节和大家分享一些经验 。