By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Replace character (UTF-8)

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
*** 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.