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

No mbstring function for finding suitable encoding.

Hello,

I am making some site, where I use UTF-8 encoding.
From PHP I send mail. But, if possible I want to send
the mail in ISO-8859-1 or KOI8-R (because still some
mailers have problem with UTF-8), but if not, just in
UTF-8.

If I look in the documentation, there is no function that
can check if a UTF-8 string can be encoded in another
encoding without loss of characters.

The function mb_check_encoding and mb_detect_encoding
have a different purpose.

Or, do I miss something?

So, I want a function:

bool mb_encoding_possible(string str, string to_encoding, string
from_encoding)

which returns TRUE if mb_convert_encoding is possible, without loss.

Regards,

Lucas Kruijswijk
Dec 11 '06 #1
2 1783
"Lucas Kruijswijk" <L.************@inter.nl.netwrote:
So, I want a function:

bool mb_encoding_possible(string str, string to_encoding, string
from_encoding)

which returns TRUE if mb_convert_encoding is possible, without loss.

/*. boolean .*/ function mb_encoding_possible(
/*. string .*/ $original,
/*. string .*/ $to_encoding,
/*. string .*/ $from_encoding)
/*
Returns TRUE if $original can be converted from $from_encoding
to $to_encoding without loosing neither char.

Very inefficient. It would be useful to return the $converted text
back to the caller, to that it has not to repeat the conversion again.
*/
{
$converted = mb_convert_encoding($original, $to_encoding, $from_encoding);
$original2 = mb_convert_encoding($converted, $from_encoding, $to_encoding);
return $original2 === $original;
}
Some optimizations requires the knowledge of the specific encodings used.
mb_substitute_character() might be useful to mark characters that cannot
be converted. For example, we can choose an ASCII control character
(most encodings do not use them for regular texts) or any other char
that do not appear in the original string, and use this char to mark
characters that cannot be converted. With only one conversion, the
presence of this char in the resulting text would mean we lost something.
Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Dec 11 '06 #2
Or add an additional parameter to 'mb_convert_encoding'.

substitute: String, will replace any character that can not be converted.
NULL - Function will return NULL, if there is at least one
character
that can not be converted.

Default is empty string.

Regards,

Lucas
"Umberto Salsi" <sa***@icosaedro.italiaschreef in bericht
news:el**********@nnrp.ngi.it...
"Lucas Kruijswijk" <L.************@inter.nl.netwrote:
>So, I want a function:

bool mb_encoding_possible(string str, string to_encoding, string
from_encoding)

which returns TRUE if mb_convert_encoding is possible, without loss.


/*. boolean .*/ function mb_encoding_possible(
/*. string .*/ $original,
/*. string .*/ $to_encoding,
/*. string .*/ $from_encoding)
/*
Returns TRUE if $original can be converted from $from_encoding
to $to_encoding without loosing neither char.

Very inefficient. It would be useful to return the $converted text
back to the caller, to that it has not to repeat the conversion again.
*/
{
$converted = mb_convert_encoding($original, $to_encoding, $from_encoding);
$original2 = mb_convert_encoding($converted, $from_encoding,
$to_encoding);
return $original2 === $original;
}
Some optimizations requires the knowledge of the specific encodings used.
mb_substitute_character() might be useful to mark characters that cannot
be converted. For example, we can choose an ASCII control character
(most encodings do not use them for regular texts) or any other char
that do not appear in the original string, and use this char to mark
characters that cannot be converted. With only one conversion, the
presence of this char in the resulting text would mean we lost something.
Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Dec 11 '06 #3

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

Similar topics

1
by: a9605473 | last post by:
A simple question. Is it possible in the python (or ipython) interpreter to review the source code of a self defined function? Thanks Erwin
4
by: ShK | last post by:
Hi, phpMyAdmin gives following error message: "The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split...
5
by: James Stroud | last post by:
Hello All, I'm using pyinstaller 1.0 (stable) on win32xp and it is not able to find the codec for several encodings (hex, base64, etc.). I resorted to writing my own for hex, just to see if I...
2
by: damezumari | last post by:
I use win 2000, php 4.4.2, phpmyadmin 2.8.0.3, iis 5.0, and mysql 5.0. When I try to run http://localhost/phpmyadmin/index.php I get the error messages: --- The mbstring PHP extension was...
3
by: news | last post by:
After installing phpMyAdmin on my Fedora Core 4 box, (Apache 2.0.54, PHP 5.0.4) we're getting this error: "The mbstring PHP extension was not found and you seem to be using a multibyte charset....
8
usafshah
by: usafshah | last post by:
i'm using phpmyadmin on Fedora core 6, everything seems to be fine but the only thing is when i open phpmyadmin at the bottom it says like The mbstring PHP extension was not found and you seem to...
1
by: nne1ssn | last post by:
I am working with a new support solution that seems to be doing well. However it is having an issue with checking a POP account for the emails. I contacted support and they state the following to...
1
by: clai83 | last post by:
(A) I am making a web application that needs to work in both an English/Japanese environment. This web application is intended to manage a company website (news releases, add new companies), and...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
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: 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...
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
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...

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.