473,396 Members | 2,030 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,396 software developers and data experts.

Replace character (UTF-8)

Hi to all,

I apologize in advance if a similar question was already posted, but I
didn't find it.
Here is my problem:

I would like to replace all the special characters ' ¾' with another
special character 'ž' in a string (retreived by an SQL). After that I
would like to update the field with the corrected string.

The table and the field are correctly set to UTF-8.

Is there a way? I have tried with the usage of functions such as
'str_replace', 'utf8_decode', 'utf8_encode' but without sucess.

Thank you in advance :)

Aug 2 '06 #1
6 14592
Pe***********@gmail.com wrote:
Hi to all,

I apologize in advance if a similar question was already posted, but I
didn't find it.
Here is my problem:

I would like to replace all the special characters ' ¾' with another
special character 'ž' in a string (retreived by an SQL). After that I
would like to update the field with the corrected string.

The table and the field are correctly set to UTF-8.

Is there a way? I have tried with the usage of functions such as
'str_replace', 'utf8_decode', 'utf8_encode' but without sucess.
Try saving the PHP file in UTF-8.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Aug 2 '06 #2
Pe***********@gmail.com wrote:
I would like to replace all the special characters ' ¾' with another
special character 'ž' in a string (retreived by an SQL). After that I
would like to update the field with the corrected string.
There're some replace functions for multibyte strings:

mb_ereg_replace - Replace regular expression with multibyte support
mb_eregi_replace - Replace regular expression with multibyte support
ignoring case

In any case, I believe PHP doesn't really need to know whether it's a
two byte char or two single byte chars*. So maybe you specify the terms
as strings and you haven't saved your file as UTF-8 you the char in the
file is not the one you think you typed :-?

(*) This doesn't mean it'll work in _all_ cases

Aug 2 '06 #3
Although is an mb_string extension for working with multibyte strings,
but in this case (replacing one string with another string) you can use
str_replace, no matter what the character set is. But, as someone above
pointed out, the PHP script must be correctly saved in UTF-8.

Recommended reading:
http://www.phpwact.org/php/i18n/charsets

kAlvaro wrote:
There're some replace functions for multibyte strings:

mb_ereg_replace - Replace regular expression with multibyte support
mb_eregi_replace - Replace regular expression with multibyte support
ignoring case
There is also an "u" (PCRE_UTF8) modifier for more powerful preg_*
functions, but in this case, str_replace is sufficient.
Michal Stankoviansky

Aug 2 '06 #4
R. Rajesh Jeba Anbiah: Yes, yes this was rhe reason. I saved the file
(with UltraEdit-32) in UTF-8 format and it worked perfectly!!! Thank
you very much.

Michal Stankoviansky:
Thank you too. The article is worth of reading :)

Thank you to all of you guys!!!

Michal Stankoviansky wrote:
Although is an mb_string extension for working with multibyte strings,
but in this case (replacing one string with another string) you can use
str_replace, no matter what the character set is. But, as someone above
pointed out, the PHP script must be correctly saved in UTF-8.

Recommended reading:
http://www.phpwact.org/php/i18n/charsets

kAlvaro wrote:
There're some replace functions for multibyte strings:

mb_ereg_replace - Replace regular expression with multibyte support
mb_eregi_replace - Replace regular expression with multibyte support
ignoring case

There is also an "u" (PCRE_UTF8) modifier for more powerful preg_*
functions, but in this case, str_replace is sufficient.
Michal Stankoviansky
Aug 2 '06 #5
*** kAlvaro escribió/wrote (2 Aug 2006 05:35:00 -0700):
you haven't saved your file as UTF-8 you the char in the
file is not the one you think you typed
Oh my God, I write like the Indians in Far West movies...
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 2 '06 #6
Alvaro G. Vicario schrieb:
*** kAlvaro escribió/wrote (2 Aug 2006 05:35:00 -0700):
>>you haven't saved your file as UTF-8 you the char in the
file is not the one you think you typed


Oh my God, I write like the Indians in Far West movies...
Interesting - I don't remember having seen any Indians write in far west
movies so far...

SCNR
Markus
Aug 3 '06 #7

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

Similar topics

0
by: JJ | last post by:
Hi, I have a little, big, boring problem :) I have a utf8 txt file to import in a MySQL db, cause I must create a web-application in PHP for reading this information on-line. I have create...
37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
5
by: Mahesha | last post by:
Hello, I need help in replacing one string pattern with another. Ex: I have a financial security expression like log(T 3.25 6/24/2004)/sqrt(T 4.5 6/19/2002) Here "T 3.25 6/24/2004" is a...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
4
by: Tim Kelley | last post by:
I am reading a text file with a streamreader. I parse out path and need to use that path in a sql statement. The path is in the file as \\servername\share\folder\filename.txt. When the line is...
10
by: Lonifasiko | last post by:
Hi, Just want to replace character at index 1 of a string with another character. Just want to replace character at that position. I thought Replace method would be overloaded with an index...
7
by: Tom de Neef | last post by:
I need to change one character at a known position in a string. In Pascal I would change the P's character of a string S into 'x' with S:='x'; In JavaScript I come no further than S =...
9
by: stomba | last post by:
Hi, I have a file in this format : 0 3 - - 10 10 1 0 0 0 11 11 I want to read this file and store in a matrix those values:
5
by: shapper | last post by:
Hello, I have a text as follows: "My email is something@something.xyz and I posted this @ 2 am" I need to replace the @ by (AT) bu only the ones that are in email addresses. All other @...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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 project—planning, coding, testing,...
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.