Question: i would like to reproduce/convert this js script to a php script, is there anyone can help me?
i think i need preg\_replace() in php and i'm really not good with it :/

this is my js simple script:

```
wysiwyg_val = $('.wysiwyg textarea').val()
.replace(/\n/g, "<br>")
.replace(/<br>/g,'[br]')
.replace(/\</g,'&lt;')
.replace(/\>/g,'&gt;')
.replace(/\{code\}/g, '<pre><code>')
.replace(/\{\/code\}/g, '</code></pre>')
.replace(/\{strong\}/g, '<strong>')
.replace(/\{\/strong\}/g, '</strong>')
.replace(/\{italic\}/g, '<i>')
.replace(/\{\/italic\}/g, '</i>')
.replace(/\{title\}/g, '<h2>')
.replace(/\{\/title\}/g, '</h2>')
.replace(/\{subtitle\}/g, '<h3>')
.replace(/\{\/subtitle\}/g, '</h3>')
.replace(/\[br\]/g,'<br>');

```

the `wysiwyg_val`, after is escaped, is passed via Ajax to a php page which can take it as `$_POST['text']`

Answer: 
```
$wysiwyg_val = 'xyz'; // your WYSIWYG input

$replacements = array(
    array('/\n/g', "<br>"),
    array('/<br>/g', '[br]'),
    array('/\</g','&lt;'),
    // and so forth.
);

foreach ($replacements as $replacement) {
    $wysiwyg_val = preg_replace($replacement[0], $replacement[1], $wysiwyg_val);
}

```
```
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

```

So just do 

```
$subject = $POST['text'];

$subject = preg_replace($pattern, $replacement, $subject);
$subject = preg_replace($pattern, $replacement, $subject);
...

```