Jump to content

Question, don't know how to explain it though

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
El_Fantastico

El_Fantastico

    Newbie

  • Members
  • PipPip
  • 18 posts
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?
Posted Image

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You would have to use Javascript I believe. I don't know enough to offer you any help though, sorry.

#3
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
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

#4
Centreri

Centreri

    Newbie

  • Members
  • PipPip
  • 28 posts
Ehh... why would you need Javascript again?

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.

Posted Image


#5
Centreri

Centreri

    Newbie

  • Members
  • PipPip
  • 28 posts
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.

Posted Image


#6
xtraze

xtraze

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 910 posts
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. ;)

#7
WillB

WillB

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts

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 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]