Connecting Tech Pros Worldwide Forums | Help | Site Map

Replace character (UTF-8)

Peter.Laganis@gmail.com
Guest
 
Posts: n/a
#1: Aug 2 '06
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 :)


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#2: Aug 2 '06

re: Replace character (UTF-8)


Peter.Laganis@gmail.com wrote:
Quote:
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/

kAlvaro
Guest
 
Posts: n/a
#3: Aug 2 '06

re: Replace character (UTF-8)


Peter.Laganis@gmail.com wrote:
Quote:
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

Michal Stankoviansky
Guest
 
Posts: n/a
#4: Aug 2 '06

re: Replace character (UTF-8)


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:
Quote:
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

Peter.Laganis@gmail.com
Guest
 
Posts: n/a
#5: Aug 2 '06

re: Replace character (UTF-8)


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:
Quote:
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:
Quote:
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
Alvaro G. Vicario
Guest
 
Posts: n/a
#6: Aug 2 '06

re: Replace character (UTF-8)


*** kAlvaro escribió/wrote (2 Aug 2006 05:35:00 -0700):
Quote:
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
--
Markus Ernst
Guest
 
Posts: n/a
#7: Aug 3 '06

re: Replace character (UTF-8)


Alvaro G. Vicario schrieb:
Quote:
*** kAlvaro escribió/wrote (2 Aug 2006 05:35:00 -0700):
>
Quote:
>>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
Closed Thread