I'm currently working on a website project I'm developping from start to scratch with a home-made content management system. The former website was running under SPIP (a french CMS) and I'm working to import the old content from the SPIP database on the new platform.
Things are running well, I'm getting all the articles, managed to code a new URL rewriting engine that keeps the old rewrited links as they were,..
The trouble I'm encountering is with the TEXT field of the articles that contains special tags. I did use str_replace to convert basic bbcode-like tags to html, but I'm encountering some troubles while trying to use preg_replace on more advanced tags.
Here is how the tag looks like. It's containted between plain text in a $texte var:
<doc30292|right>
As you see, the syntax looks like <docID|alignment>
I need to replace all the tags that looks like this by
display_doc($id,$alignment)
I do manage to get the ID or the alignment using preg_match but I do want to use preg_replace and I do not know how to do this. PCRE isn't part of my strenghts...
Any help ?
$texte=nl2br($texte);
$texte=preg_replace('#(<br */?>\s*)+#i', '<br /><br/>', $texte);
// SPIP Intertitre
$texte=str_replace("{{{","<h2>",$texte);
$texte=str_replace("}}}","</h2>",$texte);
// SPIP Gras
$texte=str_replace("{{","<b>",$texte);
$texte=str_replace("}}","</b>",$texte);
// SPIP Italic
$texte=str_replace("{","<i>",$texte);
$texte=str_replace("}","</i>",$texte);
preg_match('/<doc(.*?)\|/', $texte, $match);
var_dump($match);
echo $match[1];