Page 1 of 1

search and replace : how does [url=http://somewhere] work?

Posted: Mon Apr 05, 2004 1:43 am
by compound_eye
search and replace question
or
how does code behind the [ url=http://somewhere] thing on this site work?


i have a content management system,

which uses templates with tags to mark where the page content should be inserted.

the tags look like this:

Code: Select all

{:tag:}

so i might have a text file template that goes

Code: Select all

html to set up layout etc,{:menu:}...more layout..{:text:}
my code comes along and replaces the tag with the appropriate text

Code: Select all

<?php
// tags with the format {:tagName:} are replaced with:     $text
$template = str_replace("{:".$tagName.":}", $text, $template);
?>
and if there are any tags left over i clean them up with

Code: Select all

<?php
//clean unused tags
$template = preg_replace("/{:.*?:}/", "",$template);
?>
and that works just fine, but i would like to add the option of adding parameters inside the tags:

Code: Select all

&#123;:tag optionalInformation:&#125;
i have seen something on this message board that i pretty much does this

when i post to this message board there is a feature
that allows me to make a link by going [ url=http://somewhere]somewhere[/url]

i imagine there a gazillion ways to find the [ url] tags in a string and extract the information after the (optional) = sign,

but i was wondering if anyone has an opinion on the best way to do it.


how does this message board do it?

cheers
thanks for you help,
mat

Posted: Mon Apr 05, 2004 4:05 am
by twigletmac
You can download phpBB for free to see how they do it ;) . Probably involves regular expressions.

Mac

Posted: Mon Apr 05, 2004 11:06 am
by vigge89
yep it does, i've recently done this myslelf, check the bbCode file in phpBB and you'll see ;)