473,386 Members | 1,712 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,386 software developers and data experts.

Html-encode all characters not in the current character set

Hello

Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.

&#355 is for a Romanian letter, ţ, for example, and letter ţ
written in UTF-8 is not translated by htmlentities(), even if
I give the function the optional character-set argument, 'UTF-8'
(you can actually see the letter I typed if your system and your
news reader understand and can display ISO latin 2 characters,
encoded in utf-8).

I mean HTML documents can use characters in the entire UNICODE
set, even if the document source is written in ASCII for example,
by encoding any non-ASCII character with HTML entities.

Is there in PHP a function that will encode in HTML all non-ASCII
characters, or all non-latin1 characters, or all characters not in the
source character set ?

Thank you,
Timothy Madden
Apr 26 '07 #1
5 4869
"Timothy Madden" <te**********@gmail.comwrote in message
news:46***********************@news.sunsite.dk...
Hello

Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.

&#355 is for a Romanian letter, t, for example, and letter t
written in UTF-8 is not translated by htmlentities(), even if
I give the function the optional character-set argument, 'UTF-8'
(you can actually see the letter I typed if your system and your
news reader understand and can display ISO latin 2 characters,
encoded in utf-8).

I mean HTML documents can use characters in the entire UNICODE
set, even if the document source is written in ASCII for example,
by encoding any non-ASCII character with HTML entities.

Is there in PHP a function that will encode in HTML all non-ASCII
characters, or all non-latin1 characters, or all characters not in the
source character set ?
You may find the following link usefull;
http://au.php.net/utf8-decode
HTH
Vince
Apr 26 '07 #2
On Apr 26, 1:23 pm, Timothy Madden <terminato...@gmail.comwrote:
Hello

Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.

&#355 is for a Romanian letter, ţ, for example, and letter ţ
written in UTF-8 is not translated by htmlentities(), even if
I give the function the optional character-set argument, 'UTF-8'
(you can actually see the letter I typed if your system and your
news reader understand and can display ISO latin 2 characters,
encoded in utf-8).

I mean HTML documents can use characters in the entire UNICODE
set, even if the document source is written in ASCII for example,
by encoding any non-ASCII character with HTML entities.

Is there in PHP a function that will encode in HTML all non-ASCII
characters, or all non-latin1 characters, or all characters not in the
source character set ?

Thank you,
Timothy Madden
also mb_convert_encoding()

Apr 26 '07 #3
Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.
There are two terms of interest here: "character set" and "encoding"

ISO-8859-1 is an encoding that only covers a limited character set. So
there is no euro sign, for example. The Bad thing about ISO-8859-1 is
that some programs silently replace it with cp-1252, which is similar
but not exactly the same (it does have a euro sign).

&#355 is for a Romanian letter, ţ, for example, and letter ţ
written in UTF-8 is not translated by htmlentities(), even if
I give the function the optional character-set argument, 'UTF-8'
(you can actually see the letter I typed if your system and your
news reader understand and can display ISO latin 2 characters,
encoded in utf-8).
So you want to encode characters that are NOT in the character set you
explicitly state. If you do want those characters, why do you state an
encoding that does not cover them? If you do want those characters, use
a character set that does have them (like unicode) and an encoding that
covers them (utf-8 is fairly common).
I mean HTML documents can use characters in the entire UNICODE
set, even if the document source is written in ASCII for example,
by encoding any non-ASCII character with HTML entities.
Are you sure about that?
Is there in PHP a function that will encode in HTML all non-ASCII
characters, or all non-latin1 characters, or all characters not in the
source character set ?
The htmlentities function does have an encoding parameter, but you have
already used that. As for numeric entities, I expect them to be
encoding-specific.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Apr 27 '07 #4
Willem Bogaerts wrote:
>Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.

There are two terms of interest here: "character set" and "encoding"

ISO-8859-1 is an encoding that only covers a limited character set. So
there is no euro sign, for example. The Bad thing about ISO-8859-1 is
that some programs silently replace it with cp-1252, which is similar
but not exactly the same (it does have a euro sign).

>&#355 is for a Romanian letter, ţ, for example, and letter ţ
written in UTF-8 is not translated by htmlentities(), even if
I give the function the optional character-set argument, 'UTF-8'
(you can actually see the letter I typed if your system and your
news reader understand and can display ISO latin 2 characters,
encoded in utf-8).

So you want to encode characters that are NOT in the character set you
explicitly state. If you do want those characters, why do you state an
encoding that does not cover them? If you do want those characters, use
a character set that does have them (like unicode) and an encoding that
covers them (utf-8 is fairly common).
>I mean HTML documents can use characters in the entire UNICODE
set, even if the document source is written in ASCII for example,
by encoding any non-ASCII character with HTML entities.

Are you sure about that?
>Is there in PHP a function that will encode in HTML all non-ASCII
characters, or all non-latin1 characters, or all characters not in the
source character set ?

The htmlentities function does have an encoding parameter, but you have
already used that. As for numeric entities, I expect them to be
encoding-specific.

Best regards,
As I know ISO-8859-1 is a set (of characters).

As you can see in the official HTML 4.01 specification
http://www.w3.org/TR/html401/charset.html#h-5.1
that all HTML documents use UCS defined by ISO10646, which is
identical to UNICODE.

Numeric character references can be used whatever encoding
you chose for your document source, and they always refer to
characters in UCS by their code position.

Timothy Madden,
Romania
Apr 27 '07 #5
shimmyshack wrote:
On Apr 26, 1:23 pm, Timothy Madden <terminato...@gmail.comwrote:
>Hello

Is there a function that will allow me to
output text written in utf-8 (from db for example)
if my document has

Content-Type: text/html; charset=ISO-8859-1

I mean htmlspecialchars() and htmlentities() will only convert
characters that have an associated entity defined in HTML.
I would also like to translate all non-latin1 characters using
numeric references.
[...]
>Thank you,
Timothy Madden

also mb_convert_encoding()
Actually I think mb_encode_numericentity() is the function I need.

mb_convert_encoding() will just re-encode a string from one encoding
to another, but a Latin-1 source simply can not include Latin-2
characters no matter what encoding I chose. I need numeric character
references defined by HTML for that.

Anyway I think mb_encode_numericentitiy() will work, I just need to know
how to create a map of code-point areas for it to work, and I don't
quite understand how such an area is defined.

Thank you,
Timothy Madden,
Romania
Apr 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
1
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML...
33
by: LRW | last post by:
http://gto.ie-studios.net/index.php When you view the above site in IE, if the 1st of the three product images is tall enough to push the cell down a couple of pixels, IE somehow doesn't show...
9
by: Patient Guy | last post by:
Taking the BODY element as an example, all of its style attributes ('alink', 'vlink', 'background', 'text', etc.) are deprecated in HTML 4.01, a fact noted in the DOM Level 2 HTML specification. ...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
9
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP...
8
by: rn5a | last post by:
I have a HTML page named Index.html which is divided into 3 frames. The URL of 2 of the frames are HTML pages but the 3rd frame houses a ASP page. Now when I go to Windows Explorer, navigate to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.