在一次搜索和显示中获取多个单词.在PHP中

Get many words in one search and display. in PHP

本文关键字:获取 PHP 单词 显示 一次 搜索      更新时间:2023-09-26

我有一个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);那样工作,但我需要从数据库中获取字符串,并用数据库中存在的任何单词替换所有用户搜索的字符串行。谢谢

抱歉,还不能发表评论。

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

还可以检查PHP nl2br,而不是您正在使用的函数(LNtoBR)。