web_master Posted May 12, 2010 Share Posted May 12, 2010 Hi, how can I replace more than one character in one text? Like: ô to ő and û to ű and Û to Ű and Ô to Ő tanks in advanced T Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/ Share on other sites More sharing options...
cags Posted May 12, 2010 Share Posted May 12, 2010 I'm not sure what you mean? Can we have an example input with expected output? Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057076 Share on other sites More sharing options...
web_master Posted May 12, 2010 Author Share Posted May 12, 2010 I'm not sure what you mean? Can we have an example input with expected output? Ok, here is an examlpe text: Ôszintén mondom, mûködik. And need to looks like this after change characters: Őszintén mondom, működik. Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057086 Share on other sites More sharing options...
cags Posted May 12, 2010 Share Posted May 12, 2010 There is no simple method for doing this with a single pattern, this is not really what Regex is designed for. The easiest option would be to use an array of patterns/replacements. Since the pattern and replacement are fixed however you might be as well to simple use str_replace with an array of patterns and replacements. Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057090 Share on other sites More sharing options...
web_master Posted May 12, 2010 Author Share Posted May 12, 2010 There is no simple method for doing this with a single pattern, this is not really what Regex is designed for. The easiest option would be to use an array of patterns/replacements. Since the pattern and replacement are fixed however you might be as well to simple use str_replace with an array of patterns and replacements. So, this is the problem, that I dont know how can I do that - Ill try the simple str_replace ... but it dont work, but I don't know how can I do that with array ... Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057093 Share on other sites More sharing options...
cags Posted May 12, 2010 Share Posted May 12, 2010 $patterns = array('ô', 'û'); $replacements = array('ő', 'ű'); $output = str_replace($patterns, $replacements, $input); Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057096 Share on other sites More sharing options...
web_master Posted May 12, 2010 Author Share Posted May 12, 2010 $patterns = array('ô', 'û'); $replacements = array('ő', 'ű'); $output = str_replace($patterns, $replacements, $input); Thank You cags, Ill try it now Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057098 Share on other sites More sharing options...
web_master Posted May 12, 2010 Author Share Posted May 12, 2010 $patterns = array('ô', 'û'); $replacements = array('ő', 'ű'); $output = str_replace($patterns, $replacements, $input); Great, its work, thank You cags! Link to comment https://forums.phpfreaks.com/topic/201488-replace-more-than-one-character/#findComment-1057102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.