Supports array conversion for automatically converted character sets-PHP source code

Source: Internet
Author: User
Php code for array conversion supported by the automatic conversion character set

// The automatic conversion character set supports array conversion /******************************* * ****************************** parameter description * fContents: data source * from: data source content encoding *: the converted data content encoding ********************************** * *************************/function auto_charset ($ fContents, $ from, $ to) {$ from = strtoupper ($ from); $ to = strtoupper ($ to); if (strtoupper ($ from) === strtoupper ($) | empty ($ fContents) | (is_scalar ($ fContents )&&! Is_string ($ fContents) {// if the encoding is the same or non-string scalar, return $ fContents is not converted;} if (is_string ($ fContents )) {if (function_exists ('MB _ convert_encoding ') {return mb_convert_encoding ($ fContents, $ to, $ from);} elseif (function_exists ('iconv ')) {return iconv ($ from, $ to, $ fContents) ;}else {return $ fContents ;}} elseif (is_array ($ fContents )) {foreach ($ fContents as $ key => $ val) {$ _ key = auto_charset ($ key, $ From, $ to); $ fContents [$ _ key] = auto_charset ($ val, $ from, $ to); if ($ key! =$ _ Key) unset ($ fContents [$ key]);} return $ fContents;} else {return $ fContents ;}}

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.