Jump to content

[SOLVED] Internal Site Linking... where do I start?


Goldeneye

Recommended Posts

While working my site's BBCode today, I got the idea of Internal Site Linking. Here's what I mean:

 

BBCode: int://board=4 would output: <a href="http:/foo.bar/topiclist.php?board=4">Board 4</a>

 

BBCode: int://board=5&topic=6 would output: <a href="http:/foo.bar/messagelist.php?board=5&topic=6">Topic 6</a>

 

BBCode: int://board=5&topic=6&message=12107320191 would output: <a href="http:/foo.bar/messagelist.php?board=5&topic=6&message=12107320191">Message 12107320191</a>

 

BBCode: int://article=9 would output: <a href="http:/foo.bar/getarticle.php?article=9">Article 9</a>[/u]

 

And so on...

 

So I was wondering 1: Where I would start with this (If anyone could tell); 2: If this is even possible or something similar to this is; And 3: What you'd use to accomplish this (Loops, functions, classes, Regular Expressions, etc.).

 

A Preemptive thanks to anyone who gives guidance on this.

Id use preg_replace for this sort of thing.

 

Example code:

$str = '

Umm, int://board=4&topic=6 is intresting

hello goto int://board=4 for answer!

See int://article=9 too

int://board=4&topic=6&message=12107320191

';

$str = preg_replace('|int://board=([\d]+)&topic=([\d]+)&message=([\d]+)|i' , '<a href="http://foo.bar/topiclist.php?board=$1&topic=$2">Message $3</a>' , $str);
$str = preg_replace('|int://board=([\d]+)&topic=([\d]+)|'                  , '<a href="http://foo.bar/topiclist.php?board=$1&topic=$2">Topic $2</a>'   , $str);
$str = preg_replace('|int://board=([\d]+)|'                                , '<a href="http://foo.bar/topiclist.php?board=$1">Board $1</a>'            , $str);
$str = preg_replace('|int://article=([\d]+)|'                              , '<a href="http:/foo.bar/getarticle.php?article=$1">Article $1</a>'        , $str);


echo nl2br($str);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.