In the past few days, I encountered a small problem at work. There is a content type field that stores language. Because the data is imported from Excel, so in order to simplify the processing, many languages are separated by commas, and all languages are A string, which makes saving it much simpler. However, due to the problem of data quality at the beginning, some "Chinese" was "Mandarin Chinese". Now it is necessary to change all "Mandarin Chinese" to "Chinese".
This requires replacing part of a string. For such a problem, we usually use regular expressions to do the replacement, or use some replacement methods in PHP. It feels very troublesome to do this, and time is tight, so I thought of a lazy way, using the explode function. , use the string to be replaced as the delimiter, then connect the string to be replaced between the two array elements, and then UPDATE.
Copy code 如 Code as follows: & lt;? Php Function Replace () {
$ SQL = DB_QUERY ("Select Field_languages_value, nid from {Content_company_profile} Efield_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 introduces the solution to the problem that cf cannot full screen win7 and the PHP string replacement method, including the content of the solution to the problem that cf cannot full screen win7. I hope it will be helpful to friends who are interested in PHP tutorials.