-3

I have the following string: "English,French,German". Replacing one element in this string is no problem, doing this:

@if (strpos($language,'English') !== false)<dd>{{{ $malestr = str_replace("English", "Eng.", $language)}}}</dd>@endif

Resulting in: "Eng.,French,German"

Now the problem is I want to replace all three elements and return only one string, but I don't know how to get to this. Can you help?

-- edit: thanks to Mahammad Alabed, found the solution in your link. This worked:

{{{$result = str_replace(
  array('English', 'French', 'German'), 
  array('Eng.', 'Fr.', 'Ge.'), 
  $language
)}}}
3
  • 1
    You would read the php manual on str_replace php.net/manual/en/function.str-replace.php There is even an example. Commented May 27, 2014 at 14:43
  • Yes the str_replace is what you search for, see stackoverflow.com/questions/535143/… Commented May 27, 2014 at 14:45
  • thanks Mohammad, the solution provided in your link worked! Commented May 27, 2014 at 15:06

1 Answer 1

0
$languages = array(
     'English' => 'Eng.',
     'French'  => 'Fre.',
     'German'  => 'Ger.',
);

$malestr = str_replace(array_keys($languages), array_values($languages), $language);

This will replace all the terms you're looking for.

Sign up to request clarification or add additional context in comments.

2 Comments

Please don't encourage questions like this, asked with OP having made no effort at all.
Thanks scragar for the effort, although I got another solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.