Converting markup into HTML requires regular expressions.
Syntax • Modifiers • preg_replace() •
Tutorial
It might be worth going into "phed" and playing around with the "preg" functions (preg_match() returns 1 if a pattern is found, 0 if not) to test the viability of your regexps.
Finding a string beginning with a backslash
<?php
$pattern = '/\\\\{{/';
$string = 'A \\{{string {{here';
preg_match ($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
?>
Result (print_r($matches)):
Array
(
[0] => Array
(
[0] => \{{
[1] => 2
)
)
Finding a string not preceded by a backslash
<?php
$pattern = '/[^\\\\]{{|^{{/';
// That is: Either find two braces preceded by a character that is not
// a backslash, or find two braces not preceded by any character at all.
$string = '{{A \\{{string {{here';
preg_match_all ($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
?>
Result (print_r($matches)):
Array
(
[0] => Array
(
[0] => Array
(
[0] => {{
[1] => 0
)
[1] => Array
(
[0] => {{
[1] => 13
)
)
)