Questions tagged [strtr]

strtr is a php function that translates characters in a string, either by using an additional "to" and "from" translation string, or a single to=>from key=>value array.

37 questions
0
votes
1 answer

strtr is replacing in an unexpected way

strtr is replacing in an unexpected way. Please take a look at my code. $stringX = "Do you remember me?"; strtr($stringX, array("you" => "me", "me" => "you")); Expected output: Do me remember you. Actual output: Do me reyoumber you. How do I get…
jessica
  • 1,667
  • 1
  • 17
  • 35
0
votes
0 answers

Replace a letter with multiple instances in a word once in php array

I have created a word game in php/mysql where users are presented with a randomly selected word in a foreign language and then have to fill in missing letters (which depending on the word length are sometimes randomly removed or sometimes all…
0
votes
1 answer

OS-related strtr issue

I have this function that converts all special chars to uppercase: function uc_latin1($str) { if(!defined("LATIN1_UC_CHARS")) define("LATIN1_UC_CHARS", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ"); if(!defined("LATIN1_LC_CHARS")) …
Cristian
  • 198,401
  • 62
  • 356
  • 264
0
votes
1 answer

Using strtr inside a preg_replace?

I'd like to reformat a preg_replace() match with strtr() inside the preg_replace. Is it possible ? I did the following: $array = array("#" => "_", "/" => "-"); $output = preg_replace($regex, ''.strtr('$0', $array).'', $input); In my…
SuN
  • 1,036
  • 2
  • 12
  • 25
0
votes
3 answers

Merge two arrays given and replace them

I have a problem with this code... $text = "cat cow"; $a = array("cat", "cow"); $b = array("dog", "bull"); $c = array_combine($a, $b); $output = strtr($text, $c); This code merges the two arrays and replaces text. This is working fine but when I…
Shahbaz Singh
  • 191
  • 1
  • 9
0
votes
2 answers

simple preg_match regex needed

I am trying to preg match for tags in my strings that contain @[anyNumbers:anyNumbers:anyLetters] i am hoping to remove the @[] leaving everything inbetween as a string that i can later filter. What would be the easiest way to accomplish this? $str…
ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
-2
votes
1 answer

PHP Sanitation with MSQLI Real Escape String and STRTR Operators

The following code is a proposal for a sanitation method when passing data to a remote database through SQL and PHP. $name = strtr(mysqli_real_escape_string($connector_obj, $_POST['name']), '/\\', ' '); My question is will the MSQLI operator…
Andrew L
  • 141
  • 9
1 2
3