Ok, I have seen alot of sites, where when they a word, it automatically has a hyperlink to a certain page of that site. I was wondering if there was anyway to implement this on my site. I run a sports site and I want everytime I write the name of a team, it automatically hyperlinks to the page of that team without me having to do it manually. Is this possible?
Question, don't know how to explain it though
Started by El_Fantastico, Mar 31 2007 11:39 AM
6 replies to this topic
#1
Posted 31 March 2007 - 11:39 AM
|
|
|
#2
Guest_Jordan_*
Posted 31 March 2007 - 02:54 PM
Guest_Jordan_*
You would have to use Javascript I believe. I don't know enough to offer you any help though, sorry.
#3
Posted 31 March 2007 - 07:05 PM
I imagine it would be Javascript along with PHP. If you want to just do it, for say, your forums, I dont think it would be very difficult to pass the post content through the PHP str_replace function and replace the "hot" words with the links.
Something like this could give you a basic idea:
http://forum.codecal...tr_replace.html
Something like this could give you a basic idea:
http://forum.codecal...tr_replace.html
#4
Posted 01 April 2007 - 09:19 AM
Ehh... why would you need Javascript again?
To do this easily, it requires precise naming of files in accord to the teams.
This small script assigns the teams to an array, assigns the number of teams to a variable, and uses a for loop to display the team's name, linked to teamname.php, for each team there is. In the teamlist thing, you just do the same thing that's shown for team1 or team 2 for however many teams you want. Remember to name the files exactly the same as the team name. If those files are in another directory, you'll need something else (post again if that's the case). If those files are .html or .htm, just replace .php with whatever else there is.
To do this easily, it requires precise naming of files in accord to the teams.
<?php
$teamlist = array("team1","team2","team3");
$numberofelements = count($teamlist);
for ($i = 1; $i <= $numberofelements; $i++) {
echo "<a href=\"" . $teamlist[$i] . ".php\">" . $teamlist[$i] . "</a>";
}
?>
This small script assigns the teams to an array, assigns the number of teams to a variable, and uses a for loop to display the team's name, linked to teamname.php, for each team there is. In the teamlist thing, you just do the same thing that's shown for team1 or team 2 for however many teams you want. Remember to name the files exactly the same as the team name. If those files are in another directory, you'll need something else (post again if that's the case). If those files are .html or .htm, just replace .php with whatever else there is.

#5
Posted 01 April 2007 - 10:38 AM
Oh, and I forgot - there are many other, more efficient methods of doing it with PHP. Personally, I would just make one 'team's page and make it so that when you click on the link it redirects you to the same page but displays different content, out of a MySQL database. However, chances are you don't have a database and you don't really want to make it complicated.

#6
Posted 10 April 2007 - 06:59 AM
Hey Centreri,
Why dont you think of a javascrip to do a simple Find and replace action.
You know, to replace
Team Name
with
<a href="~~Team URL~~">Team Name</a>
Team Name can be a variable though.
I dont know much, but I think you can build a script using this theory. ;)
Why dont you think of a javascrip to do a simple Find and replace action.
You know, to replace
Team Name
with
<a href="~~Team URL~~">Team Name</a>
Team Name can be a variable though.
I dont know much, but I think you can build a script using this theory. ;)
#7
Posted 12 April 2007 - 12:06 PM
xtraze said:
Hey Centreri,
Why dont you think of a javascrip to do a simple Find and replace action.
You know, to replace
Team Name
with
<a href="~~Team URL~~">Team Name</a>
Team Name can be a variable though.
I dont know much, but I think you can build a script using this theory. ;)
Why dont you think of a javascrip to do a simple Find and replace action.
You know, to replace
Team Name
with
<a href="~~Team URL~~">Team Name</a>
Team Name can be a variable though.
I dont know much, but I think you can build a script using this theory. ;)
Why would you do that if it is written in PHP? I have always felt that when using PHP, the less JS you use, the better.
Everything in Life can be solved with an 'If/Else' statement.
Life is like one big try/catch statement, nested within a loop.
-Will
[SIGPIC][/SIGPIC]
Life is like one big try/catch statement, nested within a loop.
-Will
[SIGPIC][/SIGPIC]


Sign In
Create Account



Back to top









