How can I replace Å
with some other string using preg_replace?
Thanks!
views:
24answers:
3
+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
2010-06-25 08:48:45
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
2010-06-25 08:58:36
+1
A:
In case your goal is to replace the Entity to it's character representation, you can also use
html_entity_decode
— Convert all HTML entities to their applicable characters
Example:
echo html_entity_decode('Å', ENT_COMPAT, 'UTF-8'); // echoes Å
Gordon
2010-06-25 09:01:03
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
2010-06-26 10:36:38