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 Quote 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? Quote 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. Quote 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. Quote 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 ... Quote 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); Quote 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 Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.