如何使用nl2br删除新行后的
并将其插入到mysql表中?
我有以下情况:
我通过ssh从服务器获取接口值。此信息进入一个.txt文件,看起来像这样:
SELECT l.loan_id
, l.totalloanamt
, t.totalsecmktvalue
FROM loans l
LEFT
JOIN (
SELECT s.loan_id
, SUM(s.secmktvalue) AS totalsecmktvalue
FROM security s
GROUP
BY s.loan_id
) t
ON t.loan_id = l.loan_id
ORDER
BY l.loan_id
然后,使用nl2br,我分成几行:
"ether1 ether2 ether3 ether4"
但是,当我读到要插入数据库时,ether1
ether2
ether3
会一起出现。
我的代码:
<br/>
我尝试使用以下内容:
$output = shell_exec('cp -va test.txt ifac.s');
$options=nl2br(file_get_contents("ifac.s"));
$options=explode(" ",$options);
for($i=0;$i<count($options);$i++)
{
$options[$i] = str_replace('<br/>', '', $options[$i]);
$Add = $PDO->query("INSERT INTO info (iface) VALUES
('$options[$i]')");
echo $options[$i];
}
并且:
function replaceWithBr($str)
{
$str = trim($str);
$str = str_replace("\r\n", "", $str);
$str = str_replace("\r", "", $str);
$str = str_replace("\n", "", $str);
return $str;
}
并且:
$var = preg_replace( " /\r|\n/", "", $options[$i]);
Mysql导出:
$breaks = array("<br />","<br>","<br/>");
$old = str_ireplace($breaks, "\r\n", $options[$i]);