473,804 Members | 3,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert text

I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!

Jun 28 '06 #1
7 2542
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


This is the same question that McHenry asked today.
The answer is simple: use html_entity_dec ode():
<?php
echo html_entity_dec ode('Thuyền Và Biển');
?>

HTH.
Ruben.
Jun 28 '06 #2
It work when out in brower! But when I save to file, nothing change! :)
Ruben van Engelenburg wrote:
This is the same question that McHenry asked today.
The answer is simple: use html_entity_dec ode():
<?php
echo html_entity_dec ode('Thuyền Và Biển');
?>

HTH.
Ruben.


Jun 28 '06 #3

ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?

Jun 28 '06 #4
I want to convert it to UTF-8 encoding
Chung Leong wrote:
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?


Jun 29 '06 #5

ngocviet wrote:
I want to convert it to UTF-8 encoding
Chung Leong wrote:
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?


You will have to do it manually using preg_replace_ca llback(), as I
don't believe html_entity_dec ode() is capable of decoding such
entities. Here're the basics:

$text = preg_replace_ca llback('/&#(d+);/',
'numeric_html_e ntity_replace', $text);

function numeric_html_en tity_replace($m ) {
$unicode = (int) $m[1];
$utf8 = /* encode the Uncode value */
return $utf8
}

The tricky part is converting the Unicode value to a UTF-8 string.

Jun 29 '06 #6
"Chung Leong" <ch***********@ hotmail.com> wrote in message
news:11******** **************@ y41g2000cwy.goo glegroups.com.. .

You will have to do it manually using preg_replace_ca llback(), as I
don't believe html_entity_dec ode() is capable of decoding such
entities. Here're the basics:

$text = preg_replace_ca llback('/&#(d+);/',
'numeric_html_e ntity_replace', $text);

function numeric_html_en tity_replace($m ) {
$unicode = (int) $m[1];
$utf8 = /* encode the Uncode value */
return $utf8
}

The tricky part is converting the Unicode value to a UTF-8 string.


There's a solution for that at php.net

http://fi.php.net/manual/en/function.chr.php#55978

chr seems to be ASCII-only (which is kinda stupid if you think about it,
plenty of utf implementations these days) but "grey" had written a
workaround for it.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg)

Jun 30 '06 #7
Thanks Kimmo Laine!
It solves my problem!
Code:

function unichr($dec)
{
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
return $utf;
}

$str = "Thuyền Và Biển";
$str = preg_replace("/&#(\d{2,5});/e", "unichr($1) ;", $str);
echo $str;

Kimmo Laine wrote:
There's a solution for that at php.net

http://fi.php.net/manual/en/function.chr.php#55978

chr seems to be ASCII-only (which is kinda stupid if you think about it,
plenty of utf implementations these days) but "grey" had written a
workaround for it.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg)
Jul 2 '06 #8

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

Similar topics

3
7776
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
3
10296
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
4
49661
by: Serge Klokov | last post by:
Hello! I have a Oracle table with a BLOB field. Each field is actually a simple text file of several lines. How to get this BLOB fields in readable format? I tryied something like row.ToString() But it give result "System.Byte" instead of actual text...
3
52537
by: Jan Eliasen | last post by:
Hi I have a string, which I must convert into another string and have it utf-8 encoded. My current code looks like this; Both vDataIn and vDataOut are Objects (parameters to a function-call), and vDataIn contains a string, and that is also what vDataOut must contain when I am done.
10
8113
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
5
9652
by: Socrates | last post by:
I am interested in developing an online utility that will enable users to copy and past any image (or upload any image on the internet) to the online utility, which will then convert the image to text. The user may "convert image to text" and copy and paste the text displayed into any word document, or send the text displayed to the recipient's email address or can download the text file as a zipped text file that will be presented to...
4
4526
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
27
5157
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
3
8753
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; this produced an error
0
10789
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.