Friday, April 16, 2010

How to get automatically linked text like in Wikipedia?

If you look at wikipedia.org, you can see that the text is linked to other related articles.





I doubt this is done by hand, any idea how to do this? I would like to apply it to my http://site xuzo.com , it's a joomla site.

How to get automatically linked text like in Wikipedia?
Wikipedia is a collaborative authoring site. The word 'wiki' in today's context is referred for collaborative authoring. These web based sites will have multiple authors writing content for topics.





These sites are supported on "wiki engines" like Twiki http://www.twiki.org or mediawiki http://www.mediawiki.org . Wiki websites are not meant to be developed by Content Management Systems like Joomla, Drupal or Plone.





Through Wiki Engines you can write content which will automatically converted into HTML pages. And they provide a facility of creating web pages and links dynamically. For example in Twiki Editor if you write





*It is a Twiki Home Page*





It will be converted into a Header in the HTML page. Similarly if you write





I want to create a NewWebPage now





Twiki gives you an indication if you want to make NewWebPage as new page by putting a question mark. If you click on the question mark the editor will open with a new page. So whatever you write in "NewWebPage" will become a new page.





And If you do not want "NewWebPage" to be created you should not click the question mark and save it.





So wiki engines provide this kind of features to dynamically create web pages on the fly.





I do not think it makes sense to create this kind of feature on Joomla. Rather if you need this feature desperately use a good Wiki Engine to create your website.





A website based on Wiki Engine can be a content management system but a website based on Joomla can not give the features of Wiki.





Ram Kumar


www.rheakt.com
Reply:Wikipedia links are made by hand. If you want to automate you have to use a server side program. The first thing you have to think of is that you don't want every word to be linked, so you will have to apply the function only to the desired areas.





I can provide you with a function in PHP that apply the replacements to a string (piece of text):





function linkwords($strText, $strWord, $strPage)


{


$link = "%26lt;a href=\"".$strPage."\"%26gt;".$strWord."%26lt;/a%26gt;";


$strText = str_replace($strWord, $link, $strText);


return $strText;


}





This function will replace a piece of text ($strWord) to the same text but linked to a page ($strPage) as in Wikipedia. For example, let's supose you have a "sun glasses" sale page at www.domname.com/sunglasses.html. You can use the function like this:





$newText = linkwords($pageText, "sun glasses", "www.domname.com/sunglasses.html");





This way you have the same text on $pageText with the linked "su glasses" in the string $newText.
Reply:%26lt;a href="URL TO SITE"%26gt;My Link%26lt;/a%26gt;





http://www.w3schools.com/html/
Reply:if you use html the code is %26lt;a href="http://www.website.html"%26gt;Blue Underlined Text%26lt;/a%26gt;





the %26lt;%26gt; and the stuff inside wont show up on your page only the blue undrlined text. Edit what you need
Reply:Wikipedia uses the MediaWiki software to do this. You can't easily apply it to other sites without doing some programming. You could download MediaWiki from mediawiki.org and put your site on that instead of joomla, or you could look at the code and adapt it if you have any PHP skills.
Reply:You can use a simple PHP function to do this, although this only recognizes links to to other websites. Otherwise, each Wikipedia article is individually written, so I'm sure it is done by hand, which, isn't that hard btw.





%26lt;?php





$mytext="My websites are www.test.com and www.test2.com so check them out.";





echo addLinkTags($mytext);





function addLinkTags($str) {


$str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z... '%26lt;a href="\1" target="_blank"%26gt;\1%26lt;/a%26gt;', $str);


$str = eregi_replace('([[:space:]()[{}])(www.[-... '\1%26lt;a href="http://\2" target="_blank"%26gt;\2%26lt;


a%26gt;', $str);


$str = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0... href="mailto:\1"%26gt;\1%26lt;/a%26gt;', $str);


return $str;


}





?%26gt;


No comments:

Post a Comment