Replace character (UTF-8)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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 :)

Re: Replace character (UTF-8)

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Re: Replace character (UTF-8) wrote:
Quoted text here. Click to load it

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

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:

kAlvaro wrote:
Quoted text here. Click to load it

There is also an "u" (PCRE_UTF8) modifier for more powerful preg_*
functions, but in this case, str_replace is sufficient.

Michal Stankoviansky

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:
Quoted text here. Click to load it

Re: Replace character (UTF-8)

*** kAlvaro escribió/wrote (2 Aug 2006 05:35:00 -0700):
Quoted text here. Click to load it

Oh my God, I write like the Indians in Far West movies...

-+ - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web:
+- Mi web de humor con rayos UVA:

Re: Replace character (UTF-8)

Alvaro G. Vicario schrieb:
Quoted text here. Click to load it

Interesting - I don't remember having seen any Indians write in far west  
movies so far...


Site Timeline