How To Remove All Occurrences Of C2a0 In A String With PHP?
-
- Home
- Questions
- Tags
- Users
- Companies
- Labs
- Jobs
- Discussions
- Collectives
-
Communities for your favorite technologies. Explore all Collectives
- Teams
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Try Teams for free Explore Teams - Teams
-
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsGet early access and see previews of new features.
Learn more about Labs How to remove all occurrences of c2a0 in a string with PHP? Ask Question Asked 13 years, 1 month ago Modified 5 years, 11 months ago Viewed 18k times Part of PHP Collective 21I'm working with a CSV file which is exported from Excel.
I have a column that contains a value of 1 234,00. I need to get all whitespaces away from these kinds of columns with PHP and I've tried to do it with preg_replace("/\s*/","",$column) as well as with str_replace(" ","",$column). I was almost ready to lose it so I took a glance into the csv-file with a HEX-editor and noticed, that this space consist of two hex values, C2 and A0 which seems to be UTF-8 non-breaking space.
But I suck with encoding stuff and I'm still confused in finding a way to remove them. Any ideas?
Share Improve this question Follow asked Oct 27, 2011 at 23:01 BudwiseЯBudwiseЯ 1,8262 gold badges16 silver badges28 bronze badges Add a comment |2 Answers
Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 48 $column = str_replace("\xc2\xa0", '', $column); Share Improve this answer Follow answered Oct 27, 2011 at 23:04 phihagphihag 287k75 gold badges467 silver badges482 bronze badges 3- To whom it may be interested this works because the input is UTF-8, if the input is ISO-8895-1 or CP1252 you must use str_replace("\xA0", '', $column); Thanks to stackoverflow.com/a/33019796/260080 – Marco Demaio Commented Feb 10, 2019 at 21:19
- @MarcoDemaio Or better first, convert to UTF-8 first. Any application that works with ISO-8859-1 internally is buggy – for instance, it will not correctly handle emojis. – phihag Commented Feb 11, 2019 at 7:45
- Beware that if $column was null, it will become an empty string. – at54321 Commented Aug 2, 2021 at 6:52
You may use trim
trim($data['value'], " \t\n\r\0\x0B\xc2\xa0")Where \t\n\r\0\x0B is defualt mask, \xc2\xa0 need add
Share Improve this answer Follow edited Dec 3, 2018 at 14:05 answered Apr 7, 2015 at 11:38 Andrey VorobyevAndrey Vorobyev 8861 gold badge10 silver badges37 bronze badges 2- 2 trim also includes space in the default mask — " \t\n\r\0\x0B\xc2\xa0". – rhs Commented Mar 5, 2016 at 1:52
- 1 This might remove parts of an otherwise correct multibyte character. var_dump("\xc2\xb4AAAA"); var_dump(trim("\xc2\xb4AAAA", " \t\n\r\0\x0B\xc2\xa0")); – 0x6368 Commented Nov 7, 2019 at 17:26
Your Answer
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Draft saved Draft discardedSign up or log in
Sign up using Google Sign up using Email and Password SubmitPost as a guest
Name EmailRequired, but never shown
Post Your Answer DiscardBy clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Not the answer you're looking for? Browse other questions tagged
or ask your own question. PHP Collective Join the discussion This question is in a collective: a subcommunity defined by tags with relevant content and experts.- The Overflow Blog
- Your docs are your infrastructure
- Featured on Meta
- More network sites to see advertising test [updated with phase 2]
- We’re (finally!) going to the cloud!
Linked
10 MySQL or PHP is appending a  whenever the £ is used -1 How to remove NBSP?Related
0 Removal of special characters, a comma separated text, PHP 0 character convertion with CSV file 2 php to csv and special characters 0 Remove a line with specific characters in a variable before putting into CSV 0 find character in string from csv file using php? 1 Targeted string replace in csv file php 3 special character to csv in php 0 Remove characters in array from file CSV PHP 1 How to remove duplicates from a PHP string separated by "X"? 0 how to clean a dirty csv string using php regexHot Network Questions
- Is there a commonly used expression for adjusting a training or form of support to a person's specific situation and needs?
- How do I make a loop-de-loop without distorting the track?
- List of all sequences with certain properties
- Does ambigous license without a version refer to most recent? Is 'AGPL' currently equivalent to 'AGPL-3.0-only'?
- How to design for API use cases that need different data from the same table?
- Difference between English short stories and short English stories
- Can Martial Characters use Spell Scrolls in D&D 2024?
- Constructing WKT POINT from GeoJSON random data fields in OGR
- Why did Satan take Jesus to the Temple to jump down from?
- If Occam's razor supports naturalism over theism, then why was William of Ockham, its author, a theist and not a naturalist?
- Can this strong directional blur at wide apertures still be explained by the usual arguments?
- What's the Purpose of the IRQ on a 6502
- Align TikZ pictures horizontally
- Is Trinitarian Christian theism a simple hypothesis?
- cartridge style bottom bracket temperature range
- Are garbage-collection programming languages inherently unsafe for use in cryptography
- How is one supposed to play these notes?
- How to identify unsafe trees for climbing stand?
- How much do ebikes actually benefit from ebike specific wheels, tires, and forks?
- Can you see through a cannonball packing?
- Reality check: energy source for power armour
- Hearing the cry of a baby - abandoning practice for action?
- I am the owner of an image. I published it in Unsplash. Am I allowed to upload that same image to other sites?
- Implicit function theorem without manifolds (Steve Smale article)?
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
lang-phpTừ khóa » C2 A0 Php
-
HTML URL Encoding Reference - W3Schools
-
Rawurlencode - Manual - PHP
-
How To Remove All Occurrences Of C2a0 In A String With PHP - PHP ...
-
Php C2a0,关于php:非破坏utf-8 0xc2a0空间和preg_replace奇怪的行为
-
Search Results - =蜜穴【HX9.COM】✔️️php C2a0 Php 图书管理 ...
-
You Must Pass A State Name! - USDA NASS
-
Non-breaking Space - Wikipedia
-
ASCII Table - TechOnTheNet
-
0xa0 Php,PHP替換UTF-8的空格(0xC2 0xA0)-爱代码爱编程
-
Php - 如何用PHP删除字符串中出现的所有c2a0? | 码农俱乐部 ...
-
%25257Bsearch_term_string%25257D/%2525C2%2525AB ...
-
E-commerce Statistics For Individuals - European Commission
-
Thread: Url Encode %A0 Vs. %20 - Dynamic Drive