我试图寻找我的数据库的字符串<strong>some text here</strong>
与s<strong>ome text here</strong>
php,如何在mysql数据库中进行搜索和替换?
取代它基本上找到的第一个<strong>
然后找到第一character
,并将其放置在的<strong>
前面说不定也使用类似here
这是否够复杂? :)
感谢
我试图寻找我的数据库的字符串<strong>some text here</strong>
与s<strong>ome text here</strong>
php,如何在mysql数据库中进行搜索和替换?
取代它基本上找到的第一个<strong>
然后找到第一character
,并将其放置在的<strong>
前面说不定也使用类似here
这是否够复杂? :)
感谢
没有正则表达式在MySQL替代的支持,所以你就必须做在PHP中替换,然后做了更新(或实现某种用于MySQL的UDF,请参阅How to do a regular expression replace in MySQL?)。
在PHP中,你会使用类似(取所有行到$行集后):
foreach($rowset as $row) {
$replacement=preg_replace('/<strong>(.)/','\1<strong>',$row->fieldname,1);
myDBCall('update mytable set myfield="'.$replacement.'" where someid='.$row->someid);
}
你会使用这样的:
update `table` set `fieldname` = replace(`fieldname`,'string_to_find','string_to_replace_with')
够复杂了什么? – 2011-06-08 06:15:51
[php/mysql搜索并替换一个句子的部分]的可能重复(http://stackoverflow.com/questions/5471767/php-mysql-search-and-replace-a-parts-of-a-sentence) – 2011-06-08 06:17:36