php - 如何查找和替换 MySQL 文本字段中的整个单词?

标签 php mysql regex database string-function

我有一句话:

“如何从mysql数据库中查找和替换文本中的单词?”

和 MySQL 表 words,有 3 列 id,word 和 replaceWord。 我有超过 4000 个单词的数据库。

表格:

id     word     replaceWord
 1     text     sentence
 2     word     letter
 3     mysql    MySQL
 4     ..       ...
 5     ..       ...
 6     ..       ...

结果:

“如何从MySQL数据库中查找和替换句子中的字母?”

我知道如何在没有数据库的情况下执行此操作,但我需要数据库。

 <?php
$text="How to find and replace word in text from mysql database?";
$replaceWord=array(  "text" => "sentence", "word" => "letter", "mysql" => "MySQL");
echo strtr($tekst, $replaceWord);
?>

最佳答案

update YourTable, Words
    set YourTable.YourColumn = replace(YourTable.YourColumn, Words.word, Words.replaceWord)

关于php - 如何查找和替换 MySQL 文本字段中的整个单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4829281/

相关文章:

MYSQL - 将查找表列连接成一行

php - 为什么我的 PDO 查询失败?

正则表达式从路径中删除文件名

c - 正则表达式测试台

javascript - 更改单选按钮的事件以从 mysql 表中获取值,但不起作用

php - PHP-FFMpeg 未转换后(ffmpeg 错误)

PHP检查SSN的长度

javascript - 用户可以编辑网站javascript吗

mysql - 使用 mysql 和 node.js 更新 foreach 外部的变量值

javascript - 如何确定输入的模式是 `Int,VarChar,Date,Time...` 等