Home > Backend Development > PHP Tutorial > PHP 写资料,形成一个shell文件,去掉^M

PHP 写资料,形成一个shell文件,去掉^M

WBOY
Release: 2016-06-13 10:36:14
Original
847 people have browsed it

PHP 写文件,形成一个shell文件,去掉^M
PHP 代码:


$file_name = '/srv/cfg/sysnetwork.cfg';

$sysnetwork_str = "#!/bin/sh\n\r";

if($_REQUEST['mgt_ip']&&$_REQUEST['mgt_netmask']){
$sysnetwork_str .= '/sbin/ifconfig mgt '.$_REQUEST['mgt_ip'].' netmask '.$_REQUEST['mgt_netmask']."\n\r";
}
if($_REQUEST['ext_ip']&&$_REQUEST['ext_netmask']){
$sysnetwork_str .='/sbin/ifconfig ext '.$_REQUEST['ext_ip'].' netmask '.$_REQUEST['ext_netmask']."\n\r";
}
if($_REQUEST['gateway']){
$sysnetwork_str .= '/sbin/route add default gw '.$_REQUEST['gateway'];
}

$write_rs=file_put_contents($file_name,$sysnetwork_str);



换行用户的\n\r
形成的文件如下:
#!/bin/sh
^M/sbin/ifconfig mgt 192.168.2.45 netmask 255.255.255.0
^M/sbin/ifconfig ext 192.168.2.99 netmask 255.255.255.0
^M/sbin/route add default gw 192.168.11.1


结果shell不能执行,发现多了^M ,

怎么解决?

------解决方案--------------------
历史问题

用服务器系统下的标准换行符即可,可以用常量PHP_EOL

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template