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);



  • 2017-02-24 16:53:58

    PHP 中的Closure

    Closure,匿名函数,又称为Anonymous functions,是php5.3的时候引入的。匿名函数就是没有定义名字的函数。这点牢牢记住就能理解匿名函数的定义了。

  • 2017-03-02 09:45:27

    动态加载js和css

    开发过程中经常需要动态加载js和css,今天特意总结了一下常用的方法。

  • 2017-03-06 14:24:21

    mysql自增主键归零的方法

    如果曾经的数据都不需要的话,可以直接清空所有数据,并将自增字段恢复从1开始计数