473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Convert special characters

KeredDrahcir
426 256MB
I'd like to be able to convert speical characters to the ASCII code. There is the option to convert a quote to &quote; but I'd need to convert it to &#34. I need to be able to do this with any special character.
An even better option would be to convert &quote; directly to &#34. Is there a way to do either of these things?
Jan 22 '10 #1
3 4307
Atli
5,058 Expert 4TB
Hey.

You can use the ord function to convert a character into it's ASCII value, which you can use to construct the HTML entity.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header('content-type: text/plain; charset=utf8');
  3.  
  4. $char = '"';
  5.  
  6. $html = htmlentities($char, ENT_QUOTES, 'UTF-8');
  7. $int = ord($char);
  8. $html_int = "&#{$int};";
  9.  
  10. echo "Char: $char\n";
  11. echo "HTML: $html\n";
  12. echo "Int : $int\n";
  13. echo "Spec: $html_int\n";
  14. ?>
Jan 22 '10 #2
kovik
1,044 Expert 1GB
To convert the descriptive entity to the ASCII entity would require a translation from one to the other. You could do this by building an array of all characters with descriptive entities and their corresponding ASCII entity, and then make use of the strtr function.

You could build the array dynamically by checking all characters whose htmlentities value is not the same as their character value from the chr function.

However, HTML makes use of a much larger character set than ASCII for descriptive entities. If you do make it dynamically, consider outputting it in the same syntax as a PHP array and then saving that statically, as to avoid re-processing every time that you want to use these entities.
Jan 23 '10 #3
KeredDrahcir
426 256MB
Thanks guys. In the end I out togther an array and used that for the coversion but I may try your suggestion Atli since it should save a lot of space.

Thanks.
Feb 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
5
by: Frederik | last post by:
Hi all, I wonder if C# has a build-in utility to convert special characters (for example "&", "<", ">") to the corresponding html entities. If such a utility is not available, can someone tell...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
4
by: Kueishiong Tu | last post by:
How do I convert a managed String type to a native char type? If nothing is availbale, how do I copy the the contents of the String object to a char array?
4
by: BADEV | last post by:
I've an multi-line edit box on an html page that I use to collect detailed description information. I'd also like to display that information on an html page... How do I convert it to hmtl so...
4
by: Paw Pedersen | last post by:
When using Encoding.Convert to convert from UTF-8 to ISO646-US the special Chars like ÆØÅ are replaced with a questionmark (?). Is there any other way to convert between encodings where you can set...
1
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
10
by: annalisa | last post by:
I really need some help with langauge conversion to HTML. My translators are translating into Word and I need to convert Word to HTML. It's been awhile since I've worked with Unicode and know that...
2
by: neovantage | last post by:
hey geeks, I am using a function which convert unicode to entities. So that i can save values into mysql database into entities. This function really helps me when i display the store entity data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.