麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
关于\n在文件中换行
悬赏分:20 - 2007年08月22日

我用PHP程序生成了一个PHP文件,其中有用\n来表示换行.

[php]
<?
//......
if(!file_exists($objfile) || @filemtime($tplfile) > @filemtime($objfile)) {
$fp = fopen($tplfile, 'r');
$template = fread($fp, filesize($tplfile)+1);
fclose($fp);

$template = preg_replace("/\\{template\\s+(.+?)\\}/is", "\\n<? include template('\\\\1'); ?>\\n", $template);
$template = preg_replace("/\\{(\\\\\\$[a-zA-Z0-9_\\[\\]\\'\\"\\$\\.\\x7f-\\xff]+)\\}/s", "<? echo \\\\1; ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{function\\s+(.+?)\\}\\s*\\-\\-\\>/s", "<? echo \\\\1; ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{if\\s+(.+?)\\}\\s*\\-\\-\\>/s", "<? if(\\\\1){ ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{elseif\\s+(.+?)\\}\\s*\\-\\-\\>/s", "<? }elseif(\\\\1){ ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{else\\}\\s*\\-\\-\\>/s", "<? }else{ ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{\\/if\\}\\s*\\-\\-\\>/s", "<? } ?>", $template);
$template = preg_replace("/\\<\\!\\-\\-\\s*\\{\\/loop\\}\\s*\\-\\-\\>/s", "<? } ?>", $template);
if($file=="header"){
$template = "<? include_once '".$tpldir."templates_'.\\$charset.'.lang.php'; ?>\\n".$template;
}
$template = preg_replace("/\\?>[\\n\\r\\t]*<\\?/s", "\\n", $template);

$fp = fopen($objfile, 'w');
flock($fp, 2);
fwrite($fp, $template);
fclose($fp);
}//........
?>
[/php]
直接用editplus打开生成的文件看不到换行,
但是用highlight_file()显示这个文件的时候有换行。
不知道是怎么一回事。我该怎样才能使其换行。
如果直接用一段简单的程序用\n生成一个文件,直接打开也是看得到换行的。

[ 本帖最后由 danyja 于 2007-2-16 01:48 AM 编辑 ]



提问者:danyja   08-22 14:02
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
84 + 95 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM