|
Posted by Mike Willbanks on 10/06/48 11:23
> Basically, the table for autolinks contained this sort of data:
>
> text: BBC
> url: http://www.bbc.co.uk
>
> 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?
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
although.
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>',
$file);
}
}
As you can see I didn't really write you out the full regular expression
you can do that yourself ;)
Mike
Navigation:
[Reply to this message]
|