字符串拆分和联接从数据库中获取字符串

String split and join get strings from database

本文关键字:字符串 数据库 获取 拆分      更新时间:2023-09-26

我有一个带split和join函数的java脚本,但我所拥有的数据给了我一个"超过限制"的错误代码,所以我决定使用数据库来存储字符串并从中获取字符串。。我现有的java脚本代码就在这里。

 function myFunction()
 {
    var str = document.getElementById("entryInput");
    var entryId = str.value;
    var str = (entryId); 
    var res = str.split('how are you brother').join('how r u bro')
    .split('are you ok').join('r u ok')
    .split('what is going on').join('wag one');
    document.getElementById('translation').innerHTML=res;
 };

我搜索并找到了这个数据库连接相关的线路,但在我尝试了很多次之后,我无法使其工作,所以请帮助我…

@mysql_connect(DB_HOST, DB_USER, DB_PWD) or die(mysql_error());
@mysql_select_db(DB_NAME) or die(mysql_error());
$str = "SELECT * FROM words WHERE word_title= "%$_GET[word]%";
$str = mysql_query($query);

编辑并添加。。。。

这是脚本附带的PHP代码,它逐字逐句地从数据库中获取字符串,但我想要像javascript为我做的那样。再次获取单词split和join,这将生成一个连续的字符串。。。我只需要从这个数据库中获取字符串,并在可能的情况下在jscript中使用它。。。如果用户键入一个单词,我需要它从数据库中获取。。。这是用户将要使用的页面的链接。。用户将键入数据库中存储的不同单词的类似字符串的页面它目前只将javascript文件中的"你还好吗"翻译为"你还好吧"。所以我需要它从数据库中获取,谢谢

function Search() {
    global $rewrite;
    $_GET['word'] = trim(str_replace(Array('%', '_'), Array('', ''), $_GET['word']));
    if ($_GET['type']) {
        $word = 'noword';
        $type = $_GET['type'];
    } elseif ($_GET['by']) {
        $word = $_GET['by'];
        $type = '';
    } elseif ($_GET['word']) {
        $word = $_GET['word'];
        if ($_GET['type'] == 'full') $type = 'full';
        else $type = '';
    } else {
        $word = '';
        $type = '';
    }
    if ($word != '') {
        $GLOBALS['page_title'] = $_GET['word'] .  ' - ' . $GLOBALS['page_title'];
        if ($type == 'full') {
            $select = "* ";
            $where = "word_title LIKE '%$_GET[word]%' OR word_desc LIKE '%$_GET[word]%' ";
            $order = "word_id DESC ";
        } elseif($type == 'latest') {
            $select = '* ';
            $where = "word_title LIKE '%$_GET[word]%' ";
            $order = "word_id DESC ";
        } else {
            $select = '* ';
            $where = "word_title LIKE '" . sqlesc($word) . "%' ";
            $order = "word_title ASC ";
        }
        $q = "SELECT $select FROM `words` WHERE $where ORDER BY $order ";
    } else {
        Redirect('index.php');
    }

感谢

你应该试试这个:

$str = "SELECT * FROM words WHERE word_title LIKE "%$_GET[word]%";

$str = "SELECT * FROM words WHERE word_title REGEXP "$_GET[word]";