现在的位置: 首页 > 综合 > 正文

php字符串之间多空格,采用特殊字符分离

2013年08月25日 ⁄ 综合 ⁄ 共 372字 ⁄ 字号 评论关闭

对于java实现起来字符替换实现起来比较容易,使用replace(oldstr,newstr)就可以达到目的,那么在php中如何达到字符替换的呢?

下面请看代码:


<?php
header("content-Type: text/html; charset=utf-8");
session_start();
$file_handle = fopen("haoma.txt", "r");
$i = 0;
if($handle){
    echo "OK";
}
while(!feof($file_handle)){
    $line = fgets($file_handle);
    $line=trim(ereg_replace("[ ]{1,}","|",$line));   //采用“|”分离多空格
    $line = $line . "\n";
    echo $line;
}
fclose($file_handle);
?>

抱歉!评论已关闭.