search
HomeBackend DevelopmentXML/RSS Tutorial[XML] Solution to garbled characters in UTF8 and GB2312 encoding conversion

The audited information must be generated as an XML file, and the XML must be encoded in GB2312, because many of the collected news websites use UTF8 encoding, so garbled characters appear during the conversion process

I recently worked on a small project, and when I encountered such problems, I recorded them as a summary.
This project is divided into two parts, one is news data collection, the other is the review of the collected information, and finally the XML file is generated.
After the data collected has been edited by the user, an ACCESS file must be exported and then imported into the information review system. The field type that stores news information in the ACCESS library is the ntext type, while the corresponding field in the audit system library is the varchar (max) type. After importing, it was found that some blank characters will appear garbled, appearing as question marks (?). In fact, After subsequent testing, it turns out that this is not a blank (space) character, but a special character. What should I do? After several tests, it was found that the varchar(max) type should be changed to nvarchar(max) type, so that the imported data will no longer have such problems.
However, during the subsequent testing process, it was found that after the imported collected information was changed (through the .net program editing function), the information in the database was garbled again. After research, it was found that the insertion statement was written like this This kind of problem will not occur, such as insert into table name (news) values ​​(N'"+updated value+""), why add N? Go to Baidu and you will understand.
At this point, in my mind I finally got relief, but the following problems made me depressed...
The reviewed information must be generated in XML format, because there are many news websites collected. The website uses UTF8 encoding, so garbled characters appear during the conversion process (it's still caused by the "blank" special character). What should I do? It is said on the Internet that converting UTF8 into GB2312 is enough, but in practice, it still cannot be solved. Problem, I have been working on it all morning to solve this problem, but in the end there is no way. When I was depressed, I suddenly thought of using the debugging function of VS to see what this special character is, and finally read the value of this field in the database. After taking it out, and then converting it into a character array, content.ToCharArray(); looked at it one by one and found that the character that caused the garbled code was ' '. Pay attention to the space in the quotation marks. This is not a space, but a space that cannot be recognized in GB2312. special characters, I suddenly thought, can I replace the value of this character directly with a space? I acted immediately, and sure enough, the garbled problem was solved. I wasted half a day on this stupid thing.
Note. , you must use the value obtained from debugging (because this is the real special character that causes garbled characters). When debugging, paste the

code as follows:

content = content.Replace(" ", " ");
.

The above is the detailed content of [XML] Solution to garbled characters in UTF8 and GB2312 encoding conversion. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
RSS in XML: Unveiling the Core of Content SyndicationRSS in XML: Unveiling the Core of Content SyndicationApr 22, 2025 am 12:08 AM

The implementation of RSS in XML is to organize content through a structured XML format. 1) RSS uses XML as the data exchange format, including elements such as channel information and project list. 2) When generating RSS files, content must be organized according to specifications and published to the server for subscription. 3) RSS files can be subscribed through a reader or plug-in to automatically update the content.

Beyond the Basics: Advanced RSS Document FeaturesBeyond the Basics: Advanced RSS Document FeaturesApr 21, 2025 am 12:03 AM

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

The XML Backbone: How RSS Feeds are StructuredThe XML Backbone: How RSS Feeds are StructuredApr 20, 2025 am 12:02 AM

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

RSS & XML: Understanding the Dynamic Duo of Web ContentRSS & XML: Understanding the Dynamic Duo of Web ContentApr 19, 2025 am 12:03 AM

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS Documents: The Foundation of Web SyndicationRSS Documents: The Foundation of Web SyndicationApr 18, 2025 am 12:04 AM

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

Decoding RSS: The XML Structure of Content FeedsDecoding RSS: The XML Structure of Content FeedsApr 17, 2025 am 12:09 AM

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

How to Parse and Utilize XML-Based RSS FeedsHow to Parse and Utilize XML-Based RSS FeedsApr 16, 2025 am 12:05 AM

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS Documents: How They Deliver Your Favorite ContentRSS Documents: How They Deliver Your Favorite ContentApr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools