2011-01-14 39 views
0

微調功能全部刪除多個空格,但是當嘗試將數據保存在數據庫中它是節省更多的空間,爲什麼懇求幫助我,我卻了所有的代碼和數據庫建設,以幫助是懇求幫助我用PHP微調功能

CREATE TABLE `test`.`user` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , 
`username` VARCHAR(30) NOT NULL 
) ENGINE = MYISAM ; 

//////////////////////// 
<?php 
    $conn = mysql_connect("localhost","root",""); 
    if(!$conn){ 
     die("there is problem in" .mysql_error()); 
    } 
    $select_db = mysql_select_db("test",$conn); 
    if(!$select_db){ 
     die("there is problem in" .mysql_error()); 
    } 
?> 
<?php 
if(isset($_POST["submit"])){ 
    $fname = trim($_POST["text"]); 
    $name = trim($fname); 
    $insert = mysql_query("insert into user(username)values('{$name}')"); 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 
<form action="" method="post"> 
<input type="text" name="text" value=""/> 
<input type="submit" name="submit" value="submit"/> 
</form> 
<body> 
</body> 
</html> 
+0

請舉一個例子。 – marcog 2011-01-14 21:34:15

+0

您應該向我們展示您正在使用的數據以及您獲得的結果。另外,不要在查詢中放置未轉義的數據。 – Andrew 2011-01-14 21:35:17

回答

1

甚至比簡單使用正則表達式

$without_spaces = str_replace(" ", "", $_POST["text"]);