这就需要把一个字符串中的部分字符串替换掉。对于这样的问题,一般就是用正则表达式来做替换,或者使用php的一些替换的方法,这样做的话感觉很比较麻烦,时间又比较紧,所以就想了这样一个懒人办法,使用explode函数,把要替换的字符串做为分割符号,然后把两个数组元素中间接上要换成的字符串,然后update一下就行了。
复制代码 代码如下:
<?php
function replace(){
$sql = db_query("select field_languages_value,nid from {content_type_company_profile} where
field_languages_value like '%mandarin chinese%'");
while($result = db_fetch_object($sql)){
$a = explode("mandarin chinese",$result->field_languages_used_value);
$b = $a[].'chinese'.$a[1];
db_query(update content_type_company_profile set field_languages_used_value = '%s' where nid = %
d,$b,$result->nid);
}
}
?>