PHP clears data spaces imported by Excel

Source: Internet
Author: User
Database written directly using the Phpexcel import string

There are spaces behind what you don't know.
trim cannot be removed.

Reply content:

Database written directly using the Phpexcel import string

There are spaces behind what you don't know.
trim cannot be removed.

Preg_replace ("/(\s|\ \;| | \XC2\XA0)/"," ", $content);

Chinese space There are several kinds of: there is no simple way to solve the problem, such as the half-width of full-width space, such as the paragraph will be displayed as blank, and then let people misunderstand it is a space, so remove the space before you must first confirm that their own is not a space, I analyze the following two solutions.
(1)/[\s|] +/This can be, note | The following is the full-width space
(2) The regular replacement in MB can also try
Also note that when using Unicode, plus the regular expression descriptor U
But because there are a lot of spaces in Chinese, such as the one I encountered below, it's Unicode encoding c2a0, using the following expression will solve the problem.
$new [' content '] = preg_replace ('/^[(\xc2\xa0) |\s]+/', ' ', $new [' content ']);
Here is a detail: \xc2a0 is originally a Unicode character, but can not match multiple, can only replace one, "here may be because of the reason of the byte" then suddenly found such a way to solve the problem, in addition to avoid, Chinese space and English space mixed situation, followed by a \ S to clear.

  • 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.