CF cannot be a full-screen Win7 method of solving PHP string substitution

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.