Forum Moderators: coopster

Message Too Old, No Replies

linking words automatically

regex

         

eltreno

3:40 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Hi

I have a list of terms and my client want their content to have links to the term description if a term(which is in the terms list) appears in the content of their site

I know this is done allot on sites but the only way i can thing is to do a replace thru the content but think I would need to do a find/replace 100 times if there where 100 words in the terms list (hope that makes sense)

They want this automatic, not opting themselves what words to link via the cms, which is how I was going to do it using xsl/xml etc
Example
"This is a <link>term</link> within content"

But they want content to stay
"This is a term within content"

and when view on webpage turn into

"This is a <a href="etc">term</a> within content

Does anyone know of a neat solution?

Thanks
Trent

alce

4:02 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Google for "Wordpress acronym plug-in" and have a look at the code. It believe it is something similar to what you are looking for.

mooger35

12:00 am on Jun 28, 2006 (gmt 0)

10+ Year Member



this is what I use.

note: I shortened this down to make it easier to read so I hope i didn't make any errors.


//query database to find names for replacing

$replace = "SELECT firstname, lastname, playerid
FROM players";
$result = mysql_query($replace);

//put results into an array

while($row = mysql_fetch_row($result)) {
$myArray[$row[0]." ".$row[1]] = "<a href='page.php?playerid=".$row[2]."'>".$row[0]." ".$row[1]."</a>";
}

//query database to find text to display

$query_recap = "SELECT *
FROM recaps
WHERE `dateid` = something
LIMIT 0,1";
$recap = mysql_query($query_recap, $connectDB) or die(mysql_error());
$row_recap = mysql_fetch_assoc($recap);

//echo text replacing keys with values

echo str_replace(array_keys($myArray), array_values($myArray), nl2br($row_recap["text"]));

eltreno

3:38 am on Jun 28, 2006 (gmt 0)

10+ Year Member



Great thanks for this, I shall build these ideas in.

Cheers
Trent