I have taken 2 text boxes and 1 text area
User will be to search the content through search box
and provides by which word it should be replaced.

Scenerio 1 :

I want to replace "Good" with word "bad"  

But this code does not replace the text area content.
It rather appends with the new replaced string

what's the solution ??

```
<body>

<form id="form1" name="form1" method="post" action="">

<p>
<label for="search">Search :</label>
<input type="text" name="search" id="search" />
</p>

<p>
<label for="replace">Replace</label>
<input type="text" name="replace" id="replace" />
</p>

<p><Br />
<input type="submit" name="submit" id="submit" value="Submit" />
<label for="textarea"></label>
</p>

<p><br />
<textarea name="textarea" id="textarea" cols="45" rows="5"  >
"Good morning how are you today are you feeling Good.";
<?php

if(isset($_POST["submit"]))
{
     $search = $_POST["search"];
 $replace = $_POST["replace"];
 $textarea = $_POST["textarea"];

 $newtext = str_replace($search,$replace,$textarea);
     echo $newtext;

}

?>
   </textarea>
  </p>
</form>

</body>
</html>

```
['https://Stackoverflow.com/questions/9480338', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1361058/']
I didn't want to install a whole extensions just for this stuff and need to do a few things automatically: It's also possible to write a helperclass (or expand an existing helper) in Bundle/Twig/Extensions for example like this:

```
public function foo(\Datetime $datetime, $lang = 'de_DE', $pattern = 'd. MMMM Y')
{
    $formatter = new \IntlDateFormatter($lang, \IntlDateFormatter::LONG, \IntlDateFormatter::LONG);
    $formatter->setPattern($pattern);
    return $formatter->format($datetime);
}

```

twig-Template:

```
{{ yourDateTimeObject|foo('en_US', 'd. MMMM Y') }}

```

The result is "12. February 2014" (or "12. Februar 2014" in de\_DE and so on)
I really only wanted the day & month names to be translated according to the locale and wrote this twig extension. It accepts the normal `DateTime->format()` parameters and converts day & months names using `strftime()` if needed.

```
<?php

namespace AppBundle\Twig\Extension;

use Twig_Extension;
use Twig_SimpleFilter;
use DateTimeZone;
use DateTime;

class LocalizedDateExtension extends Twig_Extension
{
    protected static $conversionMap = [
        'D' => 'a',
        'l' => 'A',
        'M' => 'b',
        'F' => 'B',
    ];

    public function getFilters()
    {
        return [
            new Twig_SimpleFilter('localizeddate', [$this, 'localizeDate']),
        ];
    }

    protected static function createLocalizableTodo(&$formatString)
    {
        $newFormatString = '';
        $todo = [];

        $formatLength = mb_strlen($formatString);
        for ($i = 0; $i < $formatLength; $i++) {
            $char = $formatString[$i];
            if ('\'' === $char) {
                $newFormatString = $formatString[++$i]; //advance and add new character
            }
            if (array_key_exists($char, static::$conversionMap)) {
                $newFormatString.= '\!\L\O\C\A\L\I\Z\E\D\\'; //prefix char
                $todo[$char] = static::$conversionMap[$char];
            }
            $newFormatString.= $char;
        }
        $formatString = $newFormatString;
        return $todo;
    }

    public function localizeDate(DateTime $dateTime, $format, $timezone = null, $locale = null)
    {
        if (null !== $timezone && $dateTime->getTimezone()->getName() !== $timezone) {
            $dateTime = clone $dateTime;
            $dateTime->setTimezone(new DateTimeZone($timezone));
        }

        $todo = static::createLocalizableTodo($format);
        $output = $dateTime->format($format);

        //no localizeable parameters?
        if (0 === count($todo)) {
            return $output;
        }

        if ($locale !== null) {
            $currentLocale = setlocale(LC_TIME, '0');
            setlocale(LC_TIME, $locale);
        }
        if ($timezone !== null) {
            $currentTimezone = date_default_timezone_get();
            date_default_timezone_set($timezone);
        }

        //replace special parameters
        foreach ($todo as $placeholder => $parameter) {
            $output = str_replace('!LOCALIZED'.$placeholder, strftime('%'.$parameter, $dateTime->getTimestamp()), $output);
        }
        unset($parameter);

        if (isset($currentLocale)) {
            setlocale(LC_TIME, $currentLocale);
        }
        if (isset($currentTimezone)) {
            date_default_timezone_set($currentTimezone);
        }

        return $output;
    }
}

```