views:

24

answers:

3

How can I replace Å with some other string using preg_replace? Thanks!

+5  A: 

I'm assuming PHP since you say preg_replace(). You don't need to use regular expressions for this. You can simply use str_replace():

 $string = str_replace('Å', 'something else', $string);

Regular expressions are overkill for simple replacement operations like this.

Daniel Egeberg
Yea preg_match is used for matching complex strings for validation and etc, should always use this as last resort, str_replace would do just fine you might want to change the first argument to an array with the entity and literal char to make sure it replaces on all forms of the string!
RobertPitt
+1  A: 

In case your goal is to replace the Entity to it's character representation, you can also use

Example:

echo html_entity_decode('Å', ENT_COMPAT, 'UTF-8'); // echoes Å
Gordon
A: 

Thanks, guys!

I wanted to replace html entities from the 'content' field of a database table. I solved it by using the mysql REPLACE function. I didn't know it exists...

Thanks again!

cili