Goldeneye Posted May 18, 2008 Share Posted May 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/106133-solved-internal-site-linking-where-do-i-start/ Share on other sites More sharing options...
wildteen88 Posted May 18, 2008 Share Posted May 18, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/106133-solved-internal-site-linking-where-do-i-start/#findComment-544085 Share on other sites More sharing options...
Goldeneye Posted May 18, 2008 Author Share Posted May 18, 2008 Wow this seemed so much harder at first. I knew regular expression were involved, but I had no idea how to start because I thought there was going to be a whole lot more to it. Anyways, thanks a lot wildteen88. Quote Link to comment https://forums.phpfreaks.com/topic/106133-solved-internal-site-linking-where-do-i-start/#findComment-544348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.