strtr

PHP Case-insensitive equivalent of strtr

随声附和 提交于 2021-01-28 03:44:45
问题 Where I could find a case-insensitive version of strtr ? strtr is overloaded, I am talking about the following one string strtr ( string $str , array $replace_pairs ) 回答1: Use str_ireplace: str_ireplace(array_keys($replace_pairs), array_values($replace_pairs), $str); 来源: https://stackoverflow.com/questions/7529330/php-case-insensitive-equivalent-of-strtr

Conversion of strtr php function in C#

与世无争的帅哥 提交于 2019-12-22 10:29:39
问题 Need to convert this php code in C# strtr($input, '+/', '-_') Does an equivalent C# function exist? 回答1: The PHP method strtr() is translate method and not string replace method. If you want to do the same in C# then use following: As per your comments string input = "baab"; var output = input.Replace("a", "0").Replace("b","1"); Note : There is no exactly similar method like strtr() in C# . You can find more about String.Replace method here 回答2: string input ="baab"; string strfrom="ab";

exchanging values of a variable, by values of an array, but under condition

ぃ、小莉子 提交于 2019-12-09 03:21:25
问题 I have a code that compares the output with the values of the array, and only terminates the operation with words in the array: First code( just a example ) $myVar = 'essa pizza é muito gostosa, que prato de bom sabor'; $myWords=array( array('sabor','gosto','delicia'), array('saborosa','gostosa','deliciosa'), ); foreach($myWords as $words){ shuffle($words); // randomize the subarray // pipe-together the words and return just one match if(preg_match('/\K\b(?:'.implode('|',$words).')\b/',$myVar

Conversion of strtr php function in C#

血红的双手。 提交于 2019-12-06 03:21:36
Need to convert this php code in C# strtr($input, '+/', '-_') Does an equivalent C# function exist? The PHP method strtr() is translate method and not string replace method. If you want to do the same in C# then use following: As per your comments string input = "baab"; var output = input.Replace("a", "0").Replace("b","1"); Note : There is no exactly similar method like strtr() in C# . You can find more about String.Replace method here string input ="baab"; string strfrom="ab"; string strTo="01"; for(int i=0; i< strfrom.Length;i++) { input = input.Replace(strfrom[i], strTo[i]); } //you get

exchanging values of a variable, by values of an array, but under condition

☆樱花仙子☆ 提交于 2019-12-01 08:46:19
I have a code that compares the output with the values of the array, and only terminates the operation with words in the array: First code( just a example ) $myVar = 'essa pizza é muito gostosa, que prato de bom sabor'; $myWords=array( array('sabor','gosto','delicia'), array('saborosa','gostosa','deliciosa'), ); foreach($myWords as $words){ shuffle($words); // randomize the subarray // pipe-together the words and return just one match if(preg_match('/\K\b(?:'.implode('|',$words).')\b/',$myVar,$out)){ // generate "replace_pair" from matched word and a random remaining subarray word // replace

A better way to replace emoticons in PHP?

早过忘川 提交于 2019-11-27 22:29:57
Right now I am using this function for emoticons: function emoticons($text) { $icons = array( ':)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />', ':-)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />', ':D' => '<img src="/images/blank.gif" alt="smile" class="icon_laugh" />', ':d' => '<img src="/images/blank.gif" alt="laugh" class="icon_laugh" />', ';)' => '<img src="/images/blank.gif" alt="wink" class="icon_wink" />', ':P' => '<img src="/images/blank.gif" alt="tounge" class="icon_tounge" />', ':-P' => '<img src="/images/blank.gif" alt="tounge" class=

A better way to replace emoticons in PHP?

十年热恋 提交于 2019-11-26 23:12:15
问题 Right now I am using this function for emoticons: function emoticons($text) { $icons = array( ':)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />', ':-)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />', ':D' => '<img src="/images/blank.gif" alt="smile" class="icon_laugh" />', ':d' => '<img src="/images/blank.gif" alt="laugh" class="icon_laugh" />', ';)' => '<img src="/images/blank.gif" alt="wink" class="icon_wink" />', ':P' => '<img src="/images/blank

When to use strtr vs str_replace?

一世执手 提交于 2019-11-26 19:42:42
I'm having a hard time understanding when strtr would be preferable to str_replace or vice versa. It seems that it's possible to achieve the exact same results using either function, although the order in which substrings are replaced is reversed. For example: echo strtr('test string', 'st', 'XY')."\n"; echo strtr('test string', array( 's' => 'X', 't' => 'Y', 'st' => 'Z' ))."\n"; echo str_replace(array('s', 't', 'st'), array('X', 'Y', 'Z'), 'test string')."\n"; echo str_replace(array('st', 't', 's'), array('Z', 'Y', 'X'), 'test string'); This outputs YeXY XYring YeZ Zring YeXY XYring YeZ Zring

When to use strtr vs str_replace?

一曲冷凌霜 提交于 2019-11-26 05:24:49
问题 I\'m having a hard time understanding when strtr would be preferable to str_replace or vice versa. It seems that it\'s possible to achieve the exact same results using either function, although the order in which substrings are replaced is reversed. For example: echo strtr(\'test string\', \'st\', \'XY\').\"\\n\"; echo strtr(\'test string\', array( \'s\' => \'X\', \'t\' => \'Y\', \'st\' => \'Z\' )).\"\\n\"; echo str_replace(array(\'s\', \'t\', \'st\'), array(\'X\', \'Y\', \'Z\'), \'test

PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string

筅森魡賤 提交于 2019-11-26 03:21:35
问题 What I want to do is to remove all accents and umlauts from a string, turning \"lärm\" into \"larm\" or \"andré\" into \"andre\". What I tried to do was to utf8_decode the string and then use strtr on it, but since my source file is saved as UTF-8 file, I can\'t enter the ISO-8859-15 characters for all umlauts - the editor inserts the UTF-8 characters. Obviously a solution for this would be to have an include that\'s an ISO-8859-15 file, but there must be a better way than to have another