Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TGML - How To?

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
I want to make my own TGML parser

How do I search/replace TGML tags with HTML tags??

I can do basic ones ie :

Code:
function parseTGML($string) {
    $search = array ("/\[b\]/",
                     "/\[\/b\]/",
                     "/\[u\]/",
                     "/\[\/u\]/");
    $replace = array (&quot;<b>&quot;,
                      &quot;</b>&quot;,
                      &quot;<u>&quot;,
                      &quot;</u>&quot;);
    $rstring = preg_replace ($search, $replace, $string);
    return stripslashes($rstring);
}

but I want to do font tag etc where arguments will be used eg :

[ color green ] == <font color=&quot;green&quot;>

any advice appreciated Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Its ok I think i've figured it out :

function parseTGML($string) {
$search = array (&quot;/ /&quot;,
&quot;/\[COLOR=([\w\.]+)\]/&quot;,
&quot;/\[\/color\]/&quot;,
&quot;/\[font ([\w\.]+)\]/&quot;,
&quot;/\[\/font\]/&quot;,
&quot;/\[b\]/&quot;,
&quot;/\[\/b\]/&quot;,
&quot;/\[u\]/&quot;,
&quot;/\[\/u\]/&quot;);
$replace = array (&quot;&nbsp;&nbsp;&quot;,
&quot;<font color='$1'>&quot;,
&quot;</font>&quot;,
&quot;<font face='$1'>&quot;,
&quot;</font>&quot;,
&quot;<b>&quot;,
&quot;</b>&quot;,
&quot;<u>&quot;,
&quot;</u>&quot;);
$rstring = preg_replace ($search, $replace, $string);
return stripslashes($rstring);
}

Is that right? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Its ok I think i've figured it out :

function parseTGML($string) {
$search = array (&quot;/\[COLOR=([\w\.]+)\]/&quot;,
&quot;/\[\/color\]/&quot;,
&quot;/\[font ([\w\.]+)\]/&quot;,
&quot;/\[\/font\]/&quot;,
&quot;/\[b\]/&quot;,
&quot;/\[\/b\]/&quot;,
&quot;/\[u\]/&quot;,
&quot;/\[\/u\]/&quot;);
$replace = array (&quot;<font color='$1'>&quot;,
&quot;</font>&quot;,
&quot;<font face='$1'>&quot;,
&quot;</font>&quot;,
&quot;<b>&quot;,
&quot;</b>&quot;,
&quot;<u>&quot;,
&quot;</u>&quot;);
$rstring = preg_replace ($search, $replace, $string);
return stripslashes($rstring);
}

Is that right? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top