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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
compound_eye
Forum Newbie
Posts: 15
Joined: Wed Mar 17, 2004 8:42 pm

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

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can download phpBB for free to see how they do it ;) . Probably involves regular expressions.

Mac
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

yep it does, i've recently done this myslelf, check the bbCode file in phpBB and you'll see ;)
Post Reply