Hi all. AM having a little issue with regex. Not one of my strongest skills!
I'm trying to produce a simple translation system that doesn't require arrays, gettext etc. It basically has this structure:
$content=<<<CONTENT
<p>{{Dyma destun||Here's some text}}</p>
...
CONTENT;
So the page content is held in a var via heredoc syntax. That's all well and good.
My index.php is this:
include('common/config.php');
include('common/functions.php');
include($page_server);
include('templates/common.php');
echo translate($header);
echo translate($content);
echo $footer;
The translate function in the functions.php file is this:
function translate($content){
$l = $_SESSION['lang'];
$pattern = array('en'=>'/\{\{.[^(\}\})]*\|\|/','cy'=>'/\|\|.[^(\{\{)]*\}\}/');
$brackets = array('en'=>'}}','cy'=>'{{');
$content = preg_replace($pattern[$l],'',$content);
$content = str_replace($brackets[$l],'',$content);
return $content;
}
So the function searches for '{{...||' if English is the chosen language. It then deletes this and all '}}'.
Likewise, if Welsh is the chosen language if searches for '||...}}' - deletes them and all '{{'.
Now I know this isn't the most efficient way of doing a bilingual site, but it serves my purposes perfectly.
Ok, now the background's out the way, here's the problem:
There's something wrong with the regex since it messes up when it encounters a '()' or '}' or '{' - I get the
Any comments/insight/suggestions would be greatly appreciated.