我試圖使用修剪從$ _POST數組中返回的數據中刪除下劃線字符。我試過使用爲什麼我的php trim()函數不工作?
$post_Value= str_replace("_", " ", $key)
但文字似乎並沒有返回爲單個字符串。它在每個條目之間被打破。然後我試圖修剪是這樣的:
<?php
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
// Test if connection succeeded
if (mysqli_connect_errno())
{
die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
}
if (isset($_POST))
{
$str = "";
foreach($_POST as $key => $value)
{
$str = $str . $key . ",";
}
$post_Value = trim("_", $str);
}
$query = "UPDATE player_match SET categoryOption='$$post_Value' WHERE id=1";
?>
當我使用裁剪功能沒有任何反應它不會刪除_
字符。我最終的目標是將逗號分隔列表作爲單個字符串存儲在我的數據庫中。爲什麼我的trim()
功能在這種情況下不起作用?
UPDATE:發現<br/>
鑑於頁面資源,所以我不得不做以下的組合:
$post_Value= str_replace("<br_/>", "", $str);
$post_Value2= str_replace("_", " ", $post_Value);
$post_Value3= rtrim($post_Value2,",submit,");
echo $post_Value3;
$query="UPDATE player_match SET categoryOption='$post_Value3' WHERE id=1";
如果要刪除下劃線,你可以用'str_replace()函數',但第二放慢參數應該是一個空字符串,所以它應該看起來像:'str_replace(「_」,「」,$ key)'。 – marian0 2015-02-17 23:02:15