Php and links how to make them like wikipedia.org

Discussion in 'PHP' started by TheSyndicate, Jul 15, 2008.

  1. #1
    I know in wikipedia.org there is links to diffrent topics all over the pages. There is also a wordpress plug in that do the same. Is there any PHP script that can do this on my normal pages if i want to link special words to special places.
     
    TheSyndicate, Jul 15, 2008 IP
  2. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #2
    I think it using database to store the keyword and link then with regex function, replace the keyword with patern
     
    sastro, Jul 16, 2008 IP
  3. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #3
    I am no sure about wikipedia, how exactly it displays.
    But, for example your page code in varible $data.

    You can do this

    $replaces = Array(
    	'windows'    =>  "http://www.microsoft.com", 
    	'linux'      =>  "http://www.gnu.org", 
    	'scripts'    =>  "http://www.digitlpoint.com", 
    	'articles'   =>  "http://www.apitalk.com"
    );
    
    #now make replacemnts
    foreach($replaces as $k => $v) 
        $data = str_replace($k, "<a href='$v' target=_blank>$k</a>", $data);
    Code (markup):
    Then you my utilize the data contained in $data which will be highlighting the the words as links.

    regards
     
    Vooler, Jul 16, 2008 IP
    TheSyndicate likes this.
  4. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #4
    ah you do i need to add this on all the pages or this will be in the database?
     
    TheSyndicate, Jul 16, 2008 IP
  5. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #5
    This wil lbe basecode, besides if you are fetching pages data from database then simply make a page that accepts row id as

    document.php?id=124

    where 124 will be the row id in table, getch it and put data in $data adn follow the same code.

    regards
     
    Vooler, Jul 16, 2008 IP
  6. MartinGr

    MartinGr Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You will need to add this to every page, or more precisely every output you want the keywords to be replaced at.

    Of cause you could also run a script that replaces all the words in the content with links in the database (which would be faster, but definitely way more inconvenient).
     
    MartinGr, Jul 16, 2008 IP
  7. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #7
    well it will be faster then sitt and do every link by its self its only like 20 pages
     
    TheSyndicate, Jul 16, 2008 IP
  8. MartinGr

    MartinGr Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If it's only 20 pages then yes. But if you want to add another keyword you would again have to manually go through all the 20 pages again and that can get pretty boring over time.
     
    MartinGr, Jul 16, 2008 IP
  9. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #9
    Solution to such problem is simple keep the arrayin separate file and include it in the pages.
    Or maintain the keywords and relative links in a text file or database.

    I would suggest a separte php file that is included in the 20 pages.

    Besides if it is comming from database, why do you need 20 pages actually ? One pag can serve the purpose, or is the strucutre of each page different?

    regards
     
    Vooler, Jul 16, 2008 IP
  10. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #10
    Right i have one main page and put the code there :)
     
    TheSyndicate, Jul 16, 2008 IP