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
2
votes
2 answers

Why does strpos return different results?

I have the following function that transforms special accent characters (like ă) into a-zA-Z characters in a string: function tradu($sir){ $sir_aux = $sir; $diacritice = array("ă"=>"a", "â"=>"a", "î"=>"i", "Î"=>"I", "ș"=>"s",…
Hello Lili
  • 1,527
  • 1
  • 25
  • 50
2
votes
1 answer

array_merge & strtr() doesn't work

Hi I have a problem with strtr(). I am creating a website where users can add their emoticons, and call them inside their posts by typing in the special code for an emoticon. This is what I have done and it works to some extent: //FETCH FROM THE…
Dave
  • 29
  • 1
1
vote
2 answers

removing characters from array after sorting in php

I am sorting data alphabetically in PHP from a text file which works perfect, but unfortunately the textfile, which is automatically populated, contains characters like #039; which I want to have removed from the endresult. tried numerous things to…
1
vote
1 answer

How to replace multiple substrings without replacing replaced substrings?

Help or assist as to replace in my case in such variants: $string = "This is simple string"; $search = array ( "This is simple", "string", "simple", "apple" ); $replace = array ( "This is red", "apple", "false", "lemon" ); $result…
Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125
1
vote
2 answers

strtr() partially not work

I build a script that should generate an sitemap for my project. This script use strtr() to replace unwanted signs and also convert German umlauts. $ers = array( '<' => '', '>' => '', ' ' => '-', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue', 'ä' =>…
bee
  • 71
  • 10
1
vote
3 answers

Replace two words with each other simultaneously

I need to replace the word 'me' with the word 'you', and the word 'you' with the 'me' simultaneously. It works with strtr() when the 2 words aren't next to each other, but when they are, it replaces the first word, then ignores the second word. Is…
frosty
  • 2,559
  • 8
  • 37
  • 73
1
vote
3 answers

php - Merge two arrays and replace them

I want to merge two arrays and replace the text with strtr function. I was using this before $text = "cat cow"; $array = array( "cat" => "dog", "cow" => "bull" ); $output = strtr($text, $array); this returned dog bull... Now I have two arrays like…
Shahbaz Singh
  • 191
  • 1
  • 9
0
votes
1 answer

Objective-C NSString character substitution

I have a NSString category I am working on to perform character substitution similar to PHP's strtr. This method takes a string and replaces every occurrence of each character in fromString and replaces it with the character in toString with the…
TheCrypticAce
  • 173
  • 1
  • 7
0
votes
1 answer

How to rewrite video urls from /feed that have autoplay enabled

I ran into an interesting Issue today working on a Wall Feed Plugin. A majority of videos posted to the feed via youtube have autoplay enabled. "source": "http://www.youtube.com/v/IXTS79iDTNA?version=3&autohide=1&autoplay=1", I am trying to…
ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
0
votes
0 answers

PHP: strtr() memory exhausted

I have a function that checks and decodes the content from various variables: public static function decode($content, $flag=ENT_NOQUOTES){ if ( !empty($content) && is_string($content) && !is_numeric($content) && !is_array($content) &&…
Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78
0
votes
2 answers

Strtr requires an array as the second argument?

I am calling code like strtr($somevars['thisvar'], "abc") Where $somevars['thisvar'] contains a string. And it's giving me Warning: strtr() [function.strtr]: The second argument is not an array Why?
Cobra_Fast
  • 15,671
  • 8
  • 57
  • 102
0
votes
1 answer

remove string using strtr

say it if i want to remove a word like this: ',40,15,550);context2.fillText('MY_TEXT_HERE',40,20,550);context2.fillText(' so, i want to remove ',40,15,550);context2.fillText(' and ',40,20,550);context2.fillText(' if using standart strtr is we need…
0
votes
2 answers

Parsing bytes of a binary file in PHP and translate groups into a placeholder

I could use some advice - I'm parsing a binary file in php, to be specific, it's a Sega Genesis rom-file. According to the table I have made, certain bytes correspond to characters or control different stuff with the game's text-engine. There are…
Alex
  • 77
  • 7
0
votes
2 answers

How to explode URL and set "a" tag to every word(s) between "/"?

For example, if URL is http://localhost/category/news/old-stuff then this function gives me this result: newsold stuff Question: how to put every word(s) between / to tag ? Example: news old stuff Function i am using:…
Tauras
  • 3,846
  • 3
  • 21
  • 36
0
votes
2 answers

Replacing letters simultaneously with strtr

I'm trying to replace a string simultaneously with strtr but I came across a problem. If the letter being replaced simultaneously is next to another letter that is being replaced simultaneously it doesn't replace the letter after the first letter.…
jessica
  • 1,667
  • 1
  • 17
  • 35