php读取文件内容至字符串中,同时去除换行、空行、行首行尾空格(Zjmainstay原创)

yipeiwu_com6年前PHP代码库

复制代码 代码如下:

<?php  /*   *读取文件内容至字符串中,同时去除换行、行首行尾空格。   */ header("Content-type: text/html; charset=utf-8"); echo preg_replace('/((\s)*(\n)+(\s)*)/i',',',file_get_contents('./file.php'));//End_php
//输出:
aaaa,bbbb,cccc,dddd,eeee,ffff,gggg,hhhh,iiii,jjjj,kk kk,ll ll

//file.php内容:
aaaa

cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
kk kk
ll ll


//file.php替换空格(x)、Tab(T)效果
aaaa

TTTT
cccc
ddddT
xxxxxxxxxxxT
eeeexxxxxxxxxx
ffff
gggg
hhhhxxxxxxxx
xxxxxxxxiiii
xxxxxxxxjjjjxxxxxxx
kkxxxkkTT
xxxxllxxllTT
Txxxxxxxxxx
TTTxx

相关文章

php utf-8转unicode的函数第1/2页

UTF编码 UTF-8就是以8位为单元对UCS进行编码。从UCS-2到UTF-8的编码方式如下: UCS-2编码(16进制) UTF-8 字节流(二进制) 0000 - 007F 0xx...

.htaccess文件保护实例讲解

比如说,想要保护admin文件夹,经过以下两个步骤: 步骤一、可以用记事本新建文件.htaccess,输入以下内容: AuthType BasicAuth UserFile D:/App...

php中array_multisort对多维数组排序的方法

本文实例讲述了php中array_multisort对多维数组排序的方法。分享给大家供大家参考。具体实现方法如下: function sort_array($array, $keyi...

Fatal error: Call to undefined function curl_init()解决方法

首先要确定php已经扩展 在php.ini中 复制代码 代码如下: extension=php_curl.dll 还要保证 php_curl.dll 复制到php安装目录下的ext下,...

解析Win7 XAMPP apache无法启动的问题

在Win7上下载安装版的xampp,无法启动apache ,现象是短暂显示了running标志之后就停止了,日志显示WARNING:terminating worker thread 0...