【发布时间】:2014-08-06 11:51:28
【问题描述】:
您好,我在尝试将 php 变量从 shell_exec 结果保存到 mysql 数据库时遇到了一些问题。
我想在ubuntu中获取我的本地ip系统,所以我使用
<?php
$ip = shell_exec("/sbin/ifconfig eth0 | grep 'inet addr:'| cut -d: -f2 | awk '{ print $1}' | tr -d ' '");
?>
我将 $ip 变量插入 mysql 数据库,显然执行结果中有一些隐藏字符
+------------+-----------------+-------------------+------------+------------+
| monitor_id | ip_address | total_transaction | total_user | total_hits |
+------------+-----------------+-------------------+------------+------------+
| 70 |
10.151.32.187
| 5 | 0 | 4 |
+------------+-----------------+-------------------+------------+------------+
好像有很多空格,我已经用下面的语法修剪了空格:
str_replace(" ","",$ip);
和许多其他方式,但它返回相同。有人可以帮忙吗?请..
【问题讨论】:
标签: php mysql linux shell ubuntu