我有一個字符串,我可是從包含一些座標Xcode中,檢索之前刪除空行,當字符串被插入到數據庫中它顯示爲:PHP插入到數據庫
(
"37.351701,-122.105898",
"37.351945,-122.106109",
"37.352183,-122.106338"
)
我需要的字符串, :
37.351701,-122.105898,
37.351945,-122.106109,
37.352183,-122.106338
im使用str_replace函數,它消除了(),但空行被留:
//empty line
37.351701,-122.105898,
37.351945,-122.106109,
37.352183,-122.106338
//empty line
我使用的代碼,如何刪除空行?
<?php
$conn = mysql_connect($host, $user, $pass);
@mysql_select_db($db) or die("Unable to find database");
$trackArray = $_GET["trackArray"];
$trackArrayOutput = str_replace(array('"', '(' , ')', ' ', '\n', '\r', '\n\r'), '', $trackArray);
$query = "INSERT INTO routes VALUES ('', '$trackArrayOutput')";
mysql_query($query) or die (mysql_error("error"));
mysql_close();
?>
使用TRIM()函數在PHP –