1

我通过向带有函数的 url 发送请求来在 MySQL 中存储文本。

url 用 %20 编码为空格,这很好,但是当它存储在 MySQL 中时,空格被替换为下划线 _ 。

这是一个句子 -> This_is_a_sentence。

有没有办法避免这个问题?

这是代码:

    function new_experiment_reply($thread_title = '', $raven_thread_id = '', $text = '', $forum_url = '', $raven_forum_id = '')
{
    $email = $this->session->userdata('email');
    $query = $this->db->query("SELECT id FROM fn_users WHERE email='" . $email . "'");
    $fn_user_id = $query->first_row()->id;
    $query = $this->db->query("SELECT username FROM forum_users WHERE fn_user_id='" . $fn_user_id . "' AND raven_forum_id='" . $raven_forum_id . "'");
    $username = $query->first_row()->username;
    $date = date("Y-m-d H:i");
    $query = $this->db->query('INSERT INTO promo_replies(thread_title, raven_thread_id, text, forum_url, raven_forum_id, date, fn_user_id, username) VALUES("'. $thread_title .'", "'. $raven_thread_id .'", "'. $text .'", "'. $forum_url . '", "'. $raven_forum_id . '", "'. $date . '", "'. $fn_user_id . '", "'. $username . '") ');
}

变量的插入值(正如它们在 Fiddler 中看到的那样,它们应该是这样的):

$thread_title= Facebook%20vs%20Google
$raven_thread_id = 123441
$text = This%20is%20a%20sentence
$forum_url = domain.com
$raven_forum_id = 32

回显查询后,我得到以下结果:

INSERT INTO promo_replies
    (thread_title, raven_thread_id, text, forum_url, raven_forum_id, date, fn_user_id, username) 
VALUES
    ("Facebook_vs_Google", "123441", "This_is_a_sentence", "domain_com", "32", "2012-09-06 06:04", "8", "usssaa")

我准备好对代码进行抨击,所以不用担心。

4

0 回答 0