autolink function?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm re-writing a CMS system for my site and one of the features we were
very pleased with in the old *Nuke system was the Autolinks module.

Basically, the table for autolinks contained this sort of data:

text: BBC

Simple stuff; every time we entered the term BBC into our news posts,
it would autolink it like <a href="$url">$text">. I want to replicate
this function myself.

I first considered storing the values in a text file seperated by | and
then exploding out the results, but this is a bit clumsy. I was then
wondering if it would be better to simply approach this as a search and
replace when processing News submissions, meaning the server load would
effectively be lessened if the replace function only occurs once rather
than each time the page is loaded. Am I right in thinking this?

If I was to proceed with the above method, would I be able to have php
look up all the values for $text and replace $text with the code above
when processing news submissions?


Re: autolink function?

Quoted text here. Click to load it

Your options here:
Text File - Not very efficent, have to write your own syntax
Database - Very Good - More manageable than the PHP file if you want to  
add on the fly with non-technical users
PHP File - Very Good - DB would probably be better for managability  

Now lets explain this part...
With the database you can do something easy... you will probably want to  
use a regular expression to do the replace, now here is the steps:

//query db
//start loop results
//preg_replace text with link + text (make sure you make the regular  
expression use the word and not include things if they are already a link
//end loop results
//save file

as you can see pretty easy... for example a mysql example:
$result = mysql_query('select text, url from linklist');
if ($result) {
   while ($row = mysql_fetch_assoc($result)) {
     $file = preg_replace('/'.$row['text'].'/', '<a  
href="'.$row['url'].'" title="'.$row['text'].'">'.$row['text'].'</a>',  

As you can see I didn't really write you out the full regular expression  
you can do that yourself ;)


Site Timeline