[英]PHP, MySQL - find a specific part in the field and delete it
For example: In my table I have text field with following text: 例如:在我的表格中,我的文本字段包含以下文本:
The quick brown fox jumped over the lazy dog. 敏捷的棕色狐狸跳过了那只懒狗。
How can I find brown fox and delete it, so that new field value is: 我如何找到棕狐并将其删除,以便新的字段值为:
The quick jumped over the lazy dog. 敏捷者跳过了那只懒狗。
Is this possible to do with MySQL? 这可能与MySQL有关吗?
update `table`
set `field` = replace(`field`, 'brown fox ', '')
where `field` = 'The quick brown fox jumped over the lazy dog.';
EDIT: As @Cranio pointed out, we need to remove spacing on either side of 'brown fox' in order to get the anticipated result. 编辑:正如@Cranio所指出的,我们需要删除“棕狐狸”两侧的间距,以便获得预期的结果。
SELECT
CONCAT(
LEFT("the quick brown fox jumps over the lazy dog",
INSTR("the quick brown fox jumps over the lazy dog","brown fox")-1),
MID("the quick brown fox jumps over the lazy dog",
INSTR("the quick brown fox jumps over the lazy dog","brown fox")+
LENGTH("brown fox"))
)
Using fields it would be 使用字段将是
SELECT
CONCAT(
LEFT(myField,
INSTR(myField,substring)-1),
MID(myField,
INSTR(myField)+
LENGTH(substring))
)
您可以like
编辑该字段like
检索该字段,然后将其保存回来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.