在一次搜索和显示中获取许多单词。用PHP

时间:2014-04-25 15:12:48

标签: javascript php mysql database string

我有一个php脚本,用于搜索用户输入的单词并显示结果,但我需要启用它来搜索多个单词并显示它。

单词保存在数据库中。

现在我的代码只接受"word1"替换为"word2"

我需要将"word1"替换为"word2" + "word3" to "word4"和用户类型。

这是我目前的PHP代码:

function Search() {

    $q = "SELECT * FROM words WHERE word_title = '" . str_replace('_', ' ', addslashes($_GET['word'])) . "';";
    $res = mysql_query($q);
    while($row = mysql_fetch_array($res)) {
        $c.= '' . LNtoBR($row['word_desc']) . '';
    }
    $GLOBALS['content'].= $c;
    $GLOBALS['content'].= '';
}

我试过这样:

function Search() {

    $q = "SELECT * FROM words WHERE word_title = '" . str_replace('_', ' ', addslashes($_GET['word'])) . "';";
    $res = mysql_query($q);
    while($row = mysql_fetch_array($res)) {
        $c.= 'explode(' . LNtoBR($row['word_desc']) . '), implode(' . LNtoBR($row['word_desc']) . ')';
    }
    $GLOBALS['content'].= $c;
    $GLOBALS['content'].= '';
}

但它不像JavaScript接受split(something).join(something);那样工作,但我需要从数据库中获取字符串,并用我数据库中存在的任何单词替换所有用户搜索的字符串行。感谢。

1 个答案:

答案 0 :(得分:0)

抱歉,暂无法发表评论。

使用PHP str_replace搜索和替换您的单词。

另请查看PHP nl2br,而不是您正在使用的功能(LNtoBR)。