473,899 Members | 4,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14655
Pe***********@g mail.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***********@g mail.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_replac e - 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_replac e - 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_replac e - 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
2403
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 a new DB in MYSQL 4.1.1a setting CHARACTER=utf8, then I have create a table t1 with character set utf8 and some fileds also with CHARACTER=utf8.
37
10193
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 accidentally entered are properly represented when the document is served. My programming language allows me to get the ascii value for any individual character so what I am doing when a change is saved is to look at each character in the content and...
5
11351
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 variable on which I need to perform log and then divide the result with 3.980. While parsing such expressions, I need to find all occurence of date values and replace "/" character with "~" character. I need to do this only for date portion of the
6
8896
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 Regex.Replace("<stuff>text</stuff>", "<stuff>", "<stuff>\n" would give yo <stuff text</stuff
4
3062
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 read, it is in the format of \\\\servername\\share\\folder\\filename.txt. When I try to use this in my sql statement it fails because the field in the database in in the previous format. I have tried using Replace, but I have not gotten it to...
10
18649
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 parameter with which you can write wanted character at that position. But no, Replace method only allows replacing one known character with another. The problem is I don't know the character to replace, just must replace the character at a known...
7
19345
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 = S.substr(0,P-2)+'x'+S.substr(P) Is there really no more trivial way? I'm looking for the write equivalent of S.charAt(P). TIA Tom
9
8325
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
2584
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 @ shouldn't be replaced.
0
9997
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9843
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
10863
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...
0
10494
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
9666
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, and deployment—without 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...
0
5887
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4720
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4300
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.