php– 将textarea中的文本插入MySQL数据库而不会丢失格式

php– 将textarea中的文本插入MySQL数据库而不会丢失格式,第1张

概述我正在尝试将我站点上的textarea中的文本添加到MySQL数据库中.下面是将文本添加到数据库的PHP代码.if (isset($_POST['text'])) { $text = sanitizeString($_POST['text']); $text = preg_replace('/\s\s+/', ' ', $text);

我正在尝试将我站点上的textarea中的文本添加到MySQL数据库中.

下面是将文本添加到数据库的PHP代码.

if (isset($_POST['text'])){    $text = sanitizeString($_POST['text']);    $text = preg_replace('/\s\s+/',' ',$text);    $query = "SELECT * FROM profiles WHERE user='$user'";    if (MysqL_num_rows(queryMysqL($query)))    {        queryMysqL("UPDATE profiles SET text='$text' where user='$user'");    }    else    {        $query = "INSERT INTO profiles VALUES('$user','$text')";        queryMysqL($query);    }}else{    $query  = "SELECT * FROM profiles WHERE user='$user'";    $result = queryMysqL($query);    if (MysqL_num_rows($result))    {        $row  = MysqL_fetch_row($result);        $text = stripslashes($row[1]);    }    else $text = "";}$text = stripslashes(preg_replace('/\s\s+/',$text));

以下是表单的代码.