These days, work encountered a small problem, there is a content type of the field is stored in the language, because this write data is done with Excel import, so in order to deal with the simple, a lot of languages are separated by commas, all the language is a string, so the time to deposit is much simpler. However, due to the original data quality problems, a part of the "Chinese" is "Mandarin Chinese", now need to change all the "Mandarin Chinese" to "Chinese".
This requires replacing some of the strings in a string. For such a problem, the general is to use regular expressions to do the substitution, or use some of the PHP replacement method, so it feels very troublesome, time is relatively tight, so think of such a lazy way, using the Explode function, the string to be replaced as a split symbol, Then put the two array elements in the middle of the string to be replaced, and then update the line.
Copy the Code code as follows:
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);
}
}
?>
The above describes the CF can not be full-screen Win7 solution method of PHP string substitution, including the CF can not be full-screen win7 of the resolution of the content, I hope that the PHP tutorial interested in a friend helpful.